I have an Address
class, that I use in a Customer
class and in an Order
class:
public class Address
{
public Customer Customer { get; set }
...
}
public class Customer
{
...
public List<Address> Addresses { get; set;}
}
public class Order
{
...
public Customer Curstomer { get; set; }
public Address BillingAddress { get; set;}
public Address ShippingAddress { get; set;}
}
I created the migrations succesfully but when I try to update-database
I get the following error:
Introducing FOREIGN KEY constraint 'FK_Order_Address_ShippingAddressId' on table 'Order' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint or index. See previous errors.
What is the correct way of setting up such relationship? Is this modelling even correct? Because it seems strange to me that Address
is a property related to Customer
, but I'm also using it on Order
, but duplicating the addresses in an OrderAddresses
table seems wrong too.