Conditional mapping with graphdiff

c# ef-code-first entity-framework graphdiff

Question

I have following entities in my DbContext:

enter image description here

public class A
{
   public A()
   {
       Bs = new List<B>(); 
   }

   public ICollection<B> Bs { set; get; }
}   

Sometimes I Want to update a graph:

var a = dbContext.As
       .AsNoTracking()
       .Include(x=>x.Bs)
       .firstOrDefault();

var c = new C();
a.Bs.Add(c);

var d = new D();
var e1 = new E();
var e2 = new E();
d.Es.Add(e1); //<-- added new E
d.Es.Add(e2); //<-- added new E

a.Bs.Add(d);

I want to update a with its Bs(update C,D,E too) using graphdiff:

dbContext.UpdateGraph(a,map=>map.OwnedCollection(x=>x.Bs));

This updates A, Bs, Cs, Ds, but not Es.

So I think, I need to define a conditional mapping for graphdiff, to update Es too, somethings like:

dbContext.UpdateGraph(a,map=>map.OwnedCollection(x=>x.Bs.OfType<D>(), 
                                             with =>with.OwnedCollection(t=>t.Es))
                                .OwnedCollection(x=>x.Bs.OfType<C>()));

Is there any way to do this job?

1
35
9/20/2015 2:43:47 PM

Popular Answer

You can use this with graphdiff:

dbContext.UpdateGraph(a, map => map
    .OwnedCollection(b => p.Bs, with => with
    .AssociatedCollection(p => p.Es)));

see this link: GraphDiff Explanation

1
9/28/2015 10:30:43 AM


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