0

This is what I've tried.

class ReferralRegistrationConfiguration : IEntityTypeConfiguration<ReferralRegistration>
{
    public void Configure(EntityTypeBuilder<ReferralRegistration> builder)
    {
        builder.Property<long>("PlayerId");

        builder
            .HasOne(it => it.Player)
            .WithOne()
            .HasForeignKey("PlayerId")
            .IsRequired();

        builder.HasOne(it => it.Referrer).WithMany().IsRequired();
    }
}

public class ReferralRegistration : BaseEntity
{
    public Player Player { get; set; }
    public Player Referrer { get; set; }
}

 public class Player : AuditableBaseEntity
{
    public string Name { get; set; }
    public string Gender { get; set; }
    public string CountryCode { get; set; }
    public bool IsActive { get; set; }
}

Error -

You are configuring a relationship between 'ReferralRegistration' and 'Player' but have specified a foreign key on 'PlayerId'. The foreign key must be defined on a type that is part of the relationship.

I've tried many other ways but none of them are working. I just want to configure the relationship and make it non null.

honey_ramgarhia
  • 537
  • 7
  • 15

1 Answers1

0

The following example will probably solve your problem:

[Table("Customer")]  
public partial class Customer  
{  
    [DatabaseGenerated(DatabaseGeneratedOption.None)]  
    public int CustomerId  
    {  
        get;  
        set;  
    }  
    [Required]  
    [StringLength(50)]  
    public string FirstName  
    {  
        get;  
        set;  
    }  
    [Required]  
    [StringLength(50)]  
    public string LastName  
    {  
        get;  
        set;  
    }  
    [StringLength(50)]  
    public string MiddleName  
    {  
        get;  
        set;  
    }  
    public virtual CustomerDetailCustomerDetail  
    {  
        get;  
        set;  
    }  
}  
[Table("CustomerDetail")]  
public partial class CustomerDetail  
{  
    [Key]  
    [DatabaseGenerated(DatabaseGeneratedOption.None)]  
    public int CustomerId  
    {  
        get;  
        set;  
    }  
    [StringLength(255)]  
    public string EmailAddress  
    {  
        get;  
        set;  
    }  
    [StringLength(50)]  
    public string PhoneNumber  
    {  
        get;  
        set;  
    }  
    public virtual CustomerCustomer  
    {  
        get;  
        set;  
    }  
}  
Ali_Najaf
  • 11
  • 3