我不知道是否有人面对这个问题,或者只是其他问题。
我使用的是EF代码优先架构。
这是我的第一堂课:
public class PerformanceSurchargeGeneralSettings : FullAuditedEntity
{
public int PerformanceID { get; set; }
public Performance Performance { get; set; }
public int SurchargeId { get; set; }
public Surcharges Surcharge { get; set; }
}
这是第二堂课:
public class Surcharges : FullAuditedEntity
{
public string Name { get; set; }
public ICollection<PerformanceSurchargeGeneralSettings> PerformanceSurchargeGeneralSettings{ get; set; }
}
一切正常,我可以添加迁移,更新我的数据库,但如果我去表并检查外键引用,我看不到主键表。请在此处查看此屏幕截图:
我无法在主键表的下拉列表中找到新添加的Surcharge
表。
如果我为此表执行SP_help
,我可以找到所有外键,请参阅屏幕截图:
我不明白问题究竟在哪里......
答案 0 :(得分:1)
H,
更改您的课程如下;
[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; }
}
我的建议