obzekt wrote:
I understand. Now what if you have an OrderCollection of new entities and you want to add them to a customer? Will this work:
foreach (OrderEntity oe in coll)
oe.Customer = myCustomer;
or will 'coll' drop the entities after they get added to myCustomer.Orders?
You can simply do myCustomer.Orders.AddRange(coll);
and the Customer property of the order instances will be set as well.
Is that breaking change documented? It seems I missed it, and now need to review lotsa code
In the what's new -> runtime libraries:
Synching setup of entities related to eachother has been enhanced, so that also dereferencing through FK field changes will result in proper clean-up of synchronization data and references.
Though that's easily missed.
Rule of thumb: if you are doing foreach over a collection, don't change values in the object you're consuming which you pulled from the collection, in that case either use a for loop or use an intermediate list. I always use an intermediate list if I want to use a foreach statement, as it's 100% correct: a forloop also can give you bad indexes.