【发布时间】:2017-03-16 03:55:29
【问题描述】:
我有以下课程:
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; }
}
我想将引用导航属性设为只读,以确保不能通过主体实体更改依赖实体。
我试过这样:
public Blog Blog { get; }
但是当它尝试执行Include 时出现以下错误:
“无法绑定传递给 Include 运算符的表达式 '[post].Blog'。”
如何将参考导航属性设为只读但仍可包含?
【问题讨论】: