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.