自参考表中主键以外的导航属性

问题描述 投票:0回答:1

我有一个名为Customer的表,它具有两个属性ReferrerCodeOwnReferrerCode。当客户注册时,他/她可以输入另一个客户的引荐来源代码,系统将分配一个唯一的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中有没有办法建立这种关系?

我有一个名为Customer的表,它具有两个属性ReferrerCode和OwnReferrerCode。客户注册时,他/她可以输入其他客户的推荐人代码,系统将分配一个...
entity-framework entity-framework-6 one-to-many
1个回答
0
投票
正如您所解释的,客户实体可能有一个推荐人客户,因此该关系就像是一个父子关系。 child-parent optional relationship entity-framework
© www.soinside.com 2019 - 2024. All rights reserved.