I have a table named Customer
and it has two properties ReferrerCode
and OwnReferrerCode
. When a customer registers, he/she can put a referrer code of another customer and the system will assign a unique OwnReferrerCode
. Multiple customers can use a specific customer's refer code.
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; }
}
And in config file:
this.HasOptional<Customer>(s => s.ReferrerCustomer).WithMany(g => g.ReferredCustomers)
.HasForeignKey(s => s.ReferrerRewardCode);
It obviously returns this error
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.
Is there any way to do that kind of relation in EF6