C# 实体框架核心:通过导航属性组合主键
给出了以下类别:C# 实体框架核心:通过导航属性组合主键,c#,entity-framework-core,foreign-keys,composite-primary-key,ef-fluent-api,C#,Entity Framework Core,Foreign Keys,Composite Primary Key,Ef Fluent Api,给出了以下类别: public class Person{ public int ID { get; set;} public string Name { get; set;} public List<Parentship> parentChildRelations { get; set; } } public class Parentship{ public Person Parent { get; set; } public Person
public class Person{
public int ID { get; set;}
public string Name { get; set;}
public List<Parentship> parentChildRelations { get; set; }
}
public class Parentship{
public Person Parent { get; set; }
public Person Child { get; set; }
public string RelationshipType { get; set; }
public Datetime date { get; set; }
公共类人物{
公共int ID{get;set;}
公共字符串名称{get;set;}
公共列表父子关系{get;set;}
}
公共阶级亲子关系{
公共人物父项{get;set;}
公共人物子对象{get;set;}
公共字符串关系类型{get;set;}
公共日期时间日期{get;set;}
对于实体框架核心(代码优先),我想将其映射到以下表格:
服务员:
字段名
数据类型
主键
外键
身份证件
int
对
不
名字
varchar(最大值)
不
不
请尝试添加索引值并将其设置为非聚集索引
entity.HasIndex(p => new { p.Parent.ID, p.Child.ID})
.HasName("some_name_for_index")
.ForSqlServerIsClustered(false);
@GertArnold:请参阅编辑。请在发布前测试代码。这是无效的。