有两个实体Post
和Photo
。两者都有一个comment
实体的集合。
有没有办法避免下面写的(必须为实体中的每个父级mapping
定义一个属性)?Comment
public class Post
{
public string Title {get; set;}
public ICollection<Comment> Comments{get; set; }
}
public class Photo
{
public string Path{get;set;}
public ICollection<Comment> Comments{get; set; }
}
public class Comment
{
public int? PostId{get;set;}
public Virtual Post Post{get;set;}
public int? PhotoId{get;set;}
public Virtual Photo Photo{get;set;}
}