I have the following entities: Device
and Printer
public class Device
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int DeviceId { get; set; }
public int? DefaultPrinterId { get; set; }
[ForeignKey("DefaultPrinterId")]
public virtual Printer DefaultPrinter { get; set; }
}
public class Printer
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int PrinterId { get; set; }
public int? DeviceId { get; set; }
[ForeignKey("DeviceId")]
public virtual Device Device { get; set; }
}
There are 2 relationship between the Device and the Printer
- Each Printer may or may not be hosted on a specific device, this is represented by the
Device
foreign key on thePrinter
entity. This is a one to many relationship. - Each Device will be configured to use a particular printer by default. This is represented by the
DefaultPrinter
foreign key. This is a one to many relationship.
When I generate the database with Entity Framework, I get the error: "unable to determine the principal end of an association" It's not too hard to find information about how this error relates to a 1-to-1 relationships, but I haven't found anything about how this relates to two one to many relationships.
Is there any way to tell EF that I'm not trying to define a 1-to-1 relationship?