0

How can I Store ChatRoom with only the SiteId instance of full object ? thanks

 public class ChatRoom { public ObjectId Id { get; set; } public DateTime StartDate { get; set; } public **Site** **Site** { get; set; } } 
1

1 Answer 1

1

That's pretty straightforward if you're willing to change the model:

public class ChatRoom { public ObjectId Id { get; set; } public DateTime StartDate { get; set; } public ObjectId SiteId { get; set; } } 

However, that means that you need to ensure referential integrity yourself. For instance, if the Site you want to refer to hasn't been stored yet, you will first have to store the Site in the database, then store the ChatRoom with the SiteId set to the Id of the referenced Site - otherwise, there's no Id to refer to.

More importantly, that means you're no longer working with an object graph, or domain model in your code. This has impact on your entire code architecture.

For example, you can't build expressions like MyUser.ChatRoom.Site.Owner.Address.Street. That has disadvantages, because you effectively can't implement a domain model at all, but it also comes with advantages because it's unclear when the freight trains actually would talk to the database.

However, these 'freight trains' are often dangerous, because it's unclear when the respective elements are loaded from the database.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.