I'm currently following a project being developed by csharpfritz (of microsoft). It's called, "corewiki". Some form of "wikipedia" like project. Here's the link to the repository on github: CoreWiki by Jeff Fritz On the domain class for comments he writes this:
I'm trying to understand why he created an entity FromDomain class and ToDomain class:
// Main model
public class CommentDAO
{
public int Id { get; set; }
public int ArticleId { get; set; }
public virtual ArticleDAO Article { get; set; }
public string DisplayName { get; set; }
public string Email { get; set; }
[NotMapped]
public Instant Submitted { get; set; }
public string Content { get; set; }
}
public static CommentDAO FromDomain(Core.Domain.Comment comment)
{
return new CommentDAO
{
AuthorId = comment.AuthorId,
Content = comment.Content,
DisplayName = comment.DisplayName,
Email = comment.Email,
Id = comment.Id,
ArticleId = comment.ArticleId,
Submitted = comment.Submitted
};
}
public Core.Domain.Comment ToDomain()
{
return new Core.Domain.Comment
{
AuthorId = AuthorId,
Content = Content,
DisplayName = DisplayName,
Email = Email,
Id = Id,
ArticleId = this.Article.Id,
Submitted = Submitted
};
}