Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.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
Asp.net core EF CORE 2.0不兼容关系(可空外键)_Asp.net Core_Entity Framework Core - Fatal编程技术网

Asp.net core EF CORE 2.0不兼容关系(可空外键)

Asp.net core EF CORE 2.0不兼容关系(可空外键),asp.net-core,entity-framework-core,Asp.net Core,Entity Framework Core,在我们的businessslogic中,有些联系人行可能与一个账单行(0..N)有关系 这是联络班 public class ESUsersContact { [Key] public int Id { get; set; } [ForeignKey("Billing")] public int? BillingId { get; set; } public string Title { get; set; } public strin

在我们的businessslogic中,有些联系人行可能与一个账单行(0..N)有关系

这是联络班

    public class ESUsersContact
{
    [Key]
    public int Id { get; set; }

    [ForeignKey("Billing")]
    public int? BillingId { get; set; }

    public string Title { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
    public string Email { get; set; }
    public string City { get; set; }
    public string PostalCode { get; set; }
    public string Phone { get; set; }
    public string CellPhone { get; set; }
    public string Fax { get; set; }

    public ES.Enums.BusinessESCommon.Language.AllLanguage Language { get; set; }

    public virtual ICollection<ESUsersCompany> Companies { get; set; }

    public virtual ESUsersBilling Billing { get; set; }


}
公共类ESUsersContact
{
[关键]
公共int Id{get;set;}
[外键(“账单”)]
public int?BillingId{get;set;}
公共字符串标题{get;set;}
公共字符串名称{get;set;}
公共字符串地址{get;set;}
公共字符串电子邮件{get;set;}
公共字符串City{get;set;}
公共字符串PostalCode{get;set;}
公用字符串电话{get;set;}
公共字符串{get;set;}
公共字符串传真{get;set;}
public ES.Enums.BusinessESCommon.Language.AllLanguage语言{get;set;}
公共虚拟ICollection公司{get;set;}
公共虚拟ESUsersBilling{get;set;}
}
这是计费类

    [Key, Column(Order = 0)]
    [ForeignKey("Company")]
    public int CompanyId { get; set; }

    [Key, Column(Order = 1)]
    public ES.Enums.BusinessESUsers.Billing.Type Type { get; set; }

    public ES.Enums.BusinessESUsers.Billing.Payment PaymentType { get; set; }
    public ES.Enums.BusinessESUsers.Billing.Frequency PaymentFrequency  { get; set; }

    public decimal Amount { get; set; }

    public bool IsFreeTrial { get; set; }

    public DateTime FreeTrialEndDate { get; set; }

    public DateTime? NextPaymentDate { get; set; }

    public virtual ESUsersCompany Company { get; set; }

    public virtual ICollection<ESUsersContact> Contacts { get; set; }
}
[键,列(顺序=0)]
[外键(“公司”)]
public int CompanyId{get;set;}
[键,列(顺序=1)]
public ES.Enums.businessUsers.Billing.Type{get;set;}
public ES.Enums.businessUsers.Billing.PaymentPaymentType{get;set;}
public ES.Enums.businessUsers.Billing.Frequency PaymentFrequency{get;set;}
公共十进制数{get;set;}
公共bool是freetrial{get;set;}
public DateTime freetrialendate{get;set;}
公共约会时间?NextPaymentDate{get;set;}
公共虚拟ESUsers公司{get;set;}
公共虚拟ICollection联系人{get;set;}
}
但是,我在这样做时收到此错误

The relationship from 'ESUsersContact.Billing' to 'ESUsersBilling.Contacts' with foreign key properties {'BillingId' : Nullable<int>} cannot target the primary key {'CompanyId' : int, 'Type' : Type} because it is not compatible. Configure a principal key or a set of compatible foreign key properties for this relationship.
具有外键属性{'BillingId':Nullable}的从'ESUsersContact.Billing'到'ESUsersBilling.Contacts'的关系不能以主键{'CompanyId':int,'Type':Type}为目标,因为它不兼容。为此关系配置一个主键或一组兼容的外键属性。

我不明白为什么会发生错误,并说明主键{'CompanyId':int,'Type':Type}。

esuserscocontact。Billing
类有一个复合键
esuserscocontact
必须映射两个外键<代码>公司ID和类型。您不能只引用一列,因为
ESUsersContact.Billing
有两列作为键。

ESUsersContact.Billing
类有一个复合键
esuserscocontact
必须映射两个外键<代码>公司ID和类型。您不能只引用一列,因为
esuserscocontact.Billing
的键有两列。

很明显。。。谢谢你帮助我!嗯,很明显。。。谢谢你帮助我!