我有一个名为Customer
的表,它具有两个属性ReferrerCode
和OwnReferrerCode
。当客户注册时,他/她可以输入另一个客户的引荐来源代码,系统将分配一个唯一的OwnReferrerCode
。多个客户可以使用特定客户的参考代码。
public class Customer
{
[PrimaryKey]
public long CustomerId {get;set;}
public string ReferrerCode {get;set;}
public string OwnReferrerCode {get;set;}
public Customer ReferrerCustomer { get; set; }
public ICollection<Customer> ReferredCustomers { get; set; }
}
并且在配置文件中:
this.HasOptional<Customer>(s => s.ReferrerCustomer).WithMany(g => g.ReferredCustomers)
.HasForeignKey(s => s.ReferrerRewardCode);
显然返回此错误The types of all properties in the Dependent Role of a referential constraint must be the same as the corresponding property types in the Principal Role.
[[EF6
中有没有办法建立这种关系?