【发布时间】:2013-06-26 12:53:33
【问题描述】:
我有以下与 EF5 一起使用的类
public class Question
{
public Question()
{
this.Answers = new List<Answer>();
}
public int QuestionId { get; set; }
...
...
public string Title { get; set; }
public virtual ICollection<Answer> Answers { get; set; }
}
public class Answer
{
public int AnswerId { get; set; }
public string Text { get; set; }
public int QuestionId { get; set; }
public virtual Question Question { get; set; }
}
谁能告诉我为什么需要该物业:
public virtual Question Question { get; set; }
如果我从不打算进行自动延迟加载,但确实打算有时使用包含来引入该对象,那么我是否需要这样的虚拟属性:
var questions = _questionsRepository.GetAll()
.Include(a => a.Answers);
我问的原因是因为当与 Web API 一起使用时,它会给我 json 循环引用错误。
【问题讨论】:
标签: c# linq entity-framework entity-framework-4