Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional mapping with graphdiff #148

Open
msanaei opened this issue Sep 18, 2015 · 2 comments
Open

Conditional mapping with graphdiff #148

msanaei opened this issue Sep 18, 2015 · 2 comments

Comments

@msanaei
Copy link

msanaei commented Sep 18, 2015

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));

It 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?

@b9chris
Copy link
Contributor

b9chris commented Mar 17, 2016

Unless I'm mistaken about what you're asking, you can do this by using 2 maps, one with the sometimes child Entities and one without.

@msanaei
Copy link
Author

msanaei commented Mar 20, 2016

Could you write this code please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants