I have the following data model:
My business logic works with detached entities so I'm using GraphDiff to perform updates. I'm having trouble updating the PerfModes/CalcPoints association. Conceptually, Block owns CalcPoints and PerfModes, but CalcPoints can be associated with any number of PerfModes.
I'm trying to do updates at the Block level. The code I came up with doesn't throw any errors (while other attempts did) but neither does it update the PerfModes/CalcPoints association.
container.UpdateGraph(block, map => map
.OwnedCollection(b => b.HistPoints)
.OwnedCollection(b => b.CalcPoints)
.OwnedCollection(b => b.PerfModes, with => with
.OwnedCollection(p => p.FilterCriterion, with2 => with2
.OwnedCollection(fc => fc.Filters, with3 => with3
.AssociatedEntity(f => f.OperatorType)
.AssociatedEntity(f => f.CalcPoint))))
.AssociatedCollection(p => p.CalcPoints)
);
I probably don't have a full grasp of EF graphs and GraphDiff. How do I ensure that the many-to-many PerfModes/CalcPoints association gets updated correctly?
EDIT
After looking over andyp's answer, I pulled down the latest version of GraphDiff from GitHub and tried the following mappings:
container.UpdateGraph(block, map => map
.OwnedCollection(b => b.CalcPoints)
.OwnedCollection(b => b.PerfModes,
with => with.AssociatedCollection(pm => pm.CalcPoints)));
This correctly updates my PerfModes/CalcPoints association. I switched back to my original mappings and still saw the issue of the association not updating, so it seems there's a problem with trying to update the entire model at once. I'd be fine with making multiple UpdateGraph calls, but what would be the best way to break them out?
Here's a gist with relevant code and a failing unit test.
I'm inheriting the EF generated container class to create my own context with proxy creation disabled. Does that cause a problem with GraphDiff?
.AssociatedEntity(f => f.CalcPoint)
everything works as expected. I'm going to debug why that association causes problems, as I think it shouldn't - if it's a bug in GraphDiff I'll fix it..