Update Many-to-Many Association with GraphDiff

c# entity-framework-6 graphdiff

Accepted Answer

Since your mappings appeared to be accurate, I tried to replicate your problem as follows:

var calcPoint = new CalcPoint();
var block = new Block
{
    CalcPoints = new List<CalcPoint> {calcPoint},
    PerfModes = new List<PerfMode> 
    {
        new PerfMode {CalcPoints = new List<CalcPoint> {calcPoint}}
    }
};

using (var context = new TestDbContext())
{
    context.UpdateGraph(block, map => map
        .OwnedCollection(b => b.CalcPoints)
        .OwnedCollection(b => b.PerfModes, 
            with => with.AssociatedCollection(pm => pm.CalcPoints)));

    context.SaveChanges();
}

using (var context = new TestDbContext())
{
    var reloaded = context.Blocks.Include("PerfModes.CalcPoints").Single();
    Assert.AreEqual(1, reloaded.CalcPoints.Count);
    Assert.AreEqual(1, reloaded.PerfModes.Count);
    Assert.AreEqual(1, reloaded.PerfModes[0].CalcPoints.Count);

    Assert.AreEqual(reloaded.CalcPoints[0], reloaded.PerfModes[0].CalcPoints[0]);
}

Every entity is a straightforward POCO with a single int key.IDbSet<T>s on myDbContext . I didn't change anything, either.OnModelCreating(..) neither used any attributes on the navigation properties nor used the fluent API.

I have a few queries and ideas because the code I provided above is functioning as intended:

  • Is there anything you did that I didn't do (important) that you did differently?
  • You call?SaveChanges() after UpdateGraph() ? Not at all implied!
  • Do you have GraphDiff's most recent version? Please be aware that the NuGet package is very ancient; it is preferable to download the most recent source code from Github and build it yourself.
  • If your issue still exists, please update your inquiry and provide the problematic exact scenario: kindly include your state informationDbContext prior to dialingUpdateGraph() , the adjustments GraphDiff makes and the adjustments it doesn't make.

EDIT: After all, your mapping wasn't accurate, andBlock.CalcPoints once an owned collection, twice (initial call toOwnedCollection(..) ) and once as a component of a collection (the final and sole call toAssociatedCollection(..) You never instructed GraphDiff to map, thereforePerfModes.CalcPoints and it never refreshes that collection as a result.

Please move one to request that GraphDiff do it.) You should be good from the end of the line before the last line to the end of the last line (after that your indentation matches the brackets). The proper mapping appears as follows (with two closing brackets on the last line):

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))
);
2
5/28/2014 6:51:50 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow