【发布时间】:2011-07-31 22:02:19
【问题描述】:
我试图以 JSON 格式返回完全深度的对象(填充了所有外键关系),但我得到所有引用对象的空值。
这是获取对象的调用:
public ActionResult GetAll()
{
return Json(ppEFContext.Orders, JsonRequestBehavior.AllowGet);
}
这里是 Order 对象本身:
public class Order
{
public int Id { get; set; }
public Patient Patient { get; set; }
public CertificationPeriod CertificationPeriod { get; set; }
public Agency Agency { get; set; }
public Diagnosis PrimaryDiagnosis { get; set; }
public OrderApprovalStatus ApprovalStatus { get; set; }
public User Approver { get; set; }
public User Submitter { get; set; }
public DateTime ApprovalDate { get; set; }
public DateTime SubmittedDate { get; set; }
public Boolean IsDeprecated { get; set; }
}
我还没有找到关于使用 EF 4.1 Annotations 的好资源。如果你能推荐一个好的,有答案的,你可以给我链接,这对我来说就足够了!
问候,
圭多
更新
我按照 Saxman 添加了 virtual 关键字,现在是 处理循环引用 错误问题。
【问题讨论】:
-
看看这里:stackoverflow.com/questions/4251794/… OrderApprovalStatus 等是什么类型的 Enumerable。
标签: c# code-first ef-code-first entity-framework-4.1