Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架核心:通过导航属性组合主键_C#_Entity Framework Core_Foreign Keys_Composite Primary Key_Ef Fluent Api - Fatal编程技术网

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:请参阅编辑。请在发布前测试代码。这是无效的。