gpt4 book ai didi

c# - 如何在 EF 4.1 Code First 中建立外键关系

转载 作者:行者123 更新时间:2023-11-30 15:08:26 24 4
gpt4 key购买 nike

所以我整个上午都在为这个问题苦苦挣扎。我已经阅读了几篇文章,我的工作大致基于这篇文章:

http://weblogs.asp.net/manavi/archive/2011/01/23/associations-in-ef-code-first-ctp5-part-3-one-to-one-foreign-key-associations.aspx

这是我当前的错误:

A circular reference was detected while serializing an object of type 'System.Data.Entity.DynamicProxies.Order_C00CE366506BD8C6592A3CF21B9D1C5921D31C03D7322A8F6E8EAD72E113EA95'.

这是类:

public class Order
{
[Key]
public int OrderId { get; set; }

public int PatientId { get; set; }
public virtual Patient Patient { get; set; }

public int CertificationPeriodId { get; set; }
public virtual CertificationPeriod CertificationPeriod { get; set; }

public int AgencyId { get; set; }
public virtual Agency Agency { get; set; }

public int PrimaryDiagnosisId { get; set; }
public virtual Diagnosis PrimaryDiagnosis { get; set; }

public int ApprovalStatusId { get; set; }
public virtual OrderApprovalStatus ApprovalStatus { get; set; }

public int UserId { get; set; }
public virtual User Approver { get; set; }

public int SubmitterId { get; set; }
public virtual User Submitter { get; set; }

public DateTime ApprovalDate { get; set; }

public DateTime SubmittedDate { get; set; }
public Boolean IsDeprecated { get; set; }
}

我假设我已经使用“Fluent API”做了一些事情。不幸的是,我对 Fluent API 并不流利,所以我想验证这确实是缺失的部分。

谢谢,

吉多

最佳答案

您需要使用 ForeignKeyAttribute装饰您的外键属性。

关于c# - 如何在 EF 4.1 Code First 中建立外键关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5587088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com