在 Post 類中,指定可選屬性有public Blog Blog { get; set; }什么好處?
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public int Rating { get; set; }
public List<Post> Posts { get; set; }
}
public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
uj5u.com熱心網友回復:
主要好處是您可以使用 Include 而不是顯式連接表
var posts=context.Posts.Include(i=>i.Blog).ToList();
uj5u.com熱心網友回復:
如果你有一個類的物件Post,它就知道它屬于哪個博客。如果未設定此屬性,則需要搜索所有博客中的所有帖子才能找到它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/406514.html
標籤:
