Asp.net core EF CORE 2.0不兼容关系(可空外键)
在我们的businessslogic中,有些联系人行可能与一个账单行(0..N)有关系 这是联络班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
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
的键有两列。很明显。。。谢谢你帮助我!嗯,很明显。。。谢谢你帮助我!