I have two entities with one to one relationship where in target entity primary key and foreign key are same. Here is two entity and their fluent mapping.
public class Register
{
public int Id { get; set; }
public string Number { get; set; }
// N.B: Here I can't have this virtual property for my project dependencies.
//public virtual CustomerDisplay CustomerDisplay { get; set; }
}
public class CustomerDisplay
{
public int RegisterId { get; set; }
public double ReceiptViewPercent { get; set; }
public virtual Register Register { get; set; }
}
public class RegisterConfiguration : EntityConfig<Register>
{
public RegisterConfiguration(bool useIdentity, bool sqlServerCe)
: base(sqlServerCe)
{
this.HasKey(t => t.Id);
if (!useIdentity)
{
Property(d => d.Id).IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
}
this.Property(t => t.Number).IsRequired().HasMaxLength(20);
}
}
public class CustomerDisplayConfiguration: EntityConfig<CustomerDisplay>
{
public CustomerDisplayConfiguration(bool sqlServerCe)
: base(sqlServerCe)
{
this.HasKey(t => t.RegisterId);
this.HasRequired(t => t.Register).WithMany().HasForeignKey(d => d.RegisterId).WillCascadeOnDelete(false);
}
}
I am getting following error:
I have seen lots of related questions in stackoverflow but didn't find my solution. This one best match with my issue:
How to declare one to one relationship ...
Can anyone tell me how can I get rid of this issue. Thanks