我想在一个类(MarriageProfile)中为同一个类(种姓)的主键(CasteID)放置 3 个外键(三个单独的字段)。
例子:
dbo.MarriageProfile
MarriageProfileID | CasteID | NaniCasteID | DadiCasteID
1 | 1 | 3 | 5
我应该如何为此添加流利的 API: 模型是:
Public class MarriageProfile
{
---
public int CasteID { get; set; }
public virtual Caste Caste { get; set; }
public int NaniCasteID { get; set; }
public virtual Caste NaniCaste { get; set; }
public int DadiCasteID { get; set; }
public virtual Caste DadiCaste { get; set; }
---
}
public class Caste
{
[Key]
[Column(Order = 0)]
public int CasteID { get; set; }
[Key]
[Column(Order = 1)]
public string Religion { get; set; }
[Key]
[Column(Order = 2)]
public string CasteCategory { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}
我尝试过这个。但是生成的迁移文件显示了许多附加字段。
public partial class castechange : DbMigration
{
public override void Up()
{
AddColumn("dbo.UserProfile", "CasteID", c => c.Int());
AddColumn("dbo.UserProfile", "NaniCasteID", c => c.Int());
AddColumn("dbo.UserProfile", "DadiCasteID", c => c.Int());
AddColumn("dbo.UserProfile", "Caste_CasteID", c => c.Int());
AddColumn("dbo.UserProfile", "Caste_Religion", c => c.String(maxLength: 128));
AddColumn("dbo.UserProfile", "Caste_CasteCategory", c => c.String(maxLength: 128));
AddColumn("dbo.UserProfile", "NaniCaste_CasteID", c => c.Int());
AddColumn("dbo.UserProfile", "NaniCaste_Religion", c => c.String(maxLength: 128));
AddColumn("dbo.UserProfile", "NaniCaste_CasteCategory", c => c.String(maxLength: 128));
AddColumn("dbo.UserProfile", "DadiCaste_CasteID", c => c.Int());
AddColumn("dbo.UserProfile", "DadiCaste_Religion", c => c.String(maxLength: 128));
AddColumn("dbo.UserProfile", "DadiCaste_CasteCategory", c => c.String(maxLength: 128));
-----
}
它应该只包含 AddColumn 的前三行。任何帮助!