[英]SQL Server foreign key window issue for newly created EF Code first table
I don't know if anyone face this issue or it's just something else.我不知道是否有人面临这个问题,或者只是其他问题。
I am using a EF code-first architecture.我正在使用 EF 代码优先架构。
Here is my first class :这是我的第一堂课:
public class PerformanceSurchargeGeneralSettings : FullAuditedEntity
{
public int PerformanceID { get; set; }
public Performance Performance { get; set; }
public int SurchargeId { get; set; }
public Surcharges Surcharge { get; set; }
}
And here is the second class:这是第二类:
public class Surcharges : FullAuditedEntity
{
public string Name { get; set; }
public ICollection<PerformanceSurchargeGeneralSettings> PerformanceSurchargeGeneralSettings{ get; set; }
}
Everything works fine, I can add migration, update my database but if I go to table and check for foreign key reference, I can't see primary key table.一切正常,我可以添加迁移,更新我的数据库,但是如果我去表并检查外键引用,我看不到主键表。 See this screenshot here:
在此处查看此屏幕截图:
I am not able to find newly added table that is Surcharge
in the dropdown of primary key table.我无法在主键表的下拉列表中找到新添加的
Surcharge
表。
And if I execute SP_help
for this table, I can find all foreign keys, see the screenshot:如果我对这个表执行
SP_help
,我可以找到所有的外键,看截图:
I don't understand where exactly the issue is ...我不明白问题到底出在哪里......
H, H,
Change your classes as below;更改您的课程如下;
[Table("PerformanceSurchargeGeneralSettings")]
public class PerformanceSurchargeGeneralSetting : FullAuditedEntity
{
[ForeignKey("PerformanceId")]
public virtual Performance Performance { get; set; }
public int PerformanceId { get; set; }
[ForeignKey("SurchargeId")]
public virtual Surcharge Surcharge { get; set; }
public int SurchargeId { get; set; }
}
[Table("Surcharges")]
public class Surcharge : FullAuditedEntity
{
[MaxLength(128)]
public string Name { get; set; }
public virtual ICollection<PerformanceSurchargeGeneralSetting> PerformanceSurchargeGeneralSettings{ get; set; }
}
My advises我的建议
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.