I want to know what is the best way for designing my domain objects for my project.
The domain objects should be ignorant of the ORM/Framework and even the database technology (MySQL, MSSQL, and even Mongo)
And the next question comes in mind, lets say that i have two objects, Post and Comment.
This is the code for the Post object:
class Post {
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public IList<Comment> Comments { get; set; }
}
Now, my question for the Comment object is should it include a Post Id or just a Post object?
class Comment {
public int Id { get; set; }
public string Content { get; set; }
public Post Post { get; set; }
public int PostId { get; set; } // Should i include it?
}
Is it a good practice to include the Id of the relational object or just its domain object?
Another concern is for no sql database like mongodb. If i store my data in mongodb, what Post object will the Comment object reference? In mongodb there is no relationship between post and comments, any post includes list of comments, but the comments themselves are ignorant of the post they are part of. So what is the best way to make those domain classes compatible both with Sql based database and NoSql databases?
Thank you