0
votes

I have two tables.
Orders and OrderLines
Orders has an ID property.
OrderLines has an ID and OrderID property.

So 1 order can have many order lines.

When I add OrderLines to the entity model I set "Entity Key = false" on the "ID" field.
I set "Entity Key = true" on the "OrderID" field.
I then add a new association.
OrderLines multiplicity = many and Orders multiplicity = 1. No navigation property and no add foreign key properties.
Referential Constraint..
Principal OrderLines OrderID -- Dependent Order ID.

Hit save and then I will get "Multiplicity is not valid in role 'OrderLines'... Valid values for multiplicity for Principal Role are '0..1' or 1'."
If I change it from 1 to say '0..1' then I will get the same error.

1

1 Answers

0
votes

Well I had to do the following to get it to work correctly.

  1. Make sure that both the ID in Orders and the ID in OrderLines has "StoreGeneratedPattern = Identity"
  2. Make sure the OrderID in OrderLines has "Entity Key = False"
  3. Create a 1-to-many where 1 is on the Order and many is on the OrderLines

This site is a little helpful for anyone trying to understand Entity Framework relations.
http://weblogs.asp.net/ricardoperes/entity-framework-code-first-relations