0

I have some models:

public class RootEntity
{
    public int Id {get; set;}

    public virtual ICollection<AbstractEntity> CollectionA {get; set;}
}

public abstract class AbstractEntity
{
    public int Id {get; set;}
}

public class DerivedEntityA : AbstractEntity
{
    public virtual ICollection<AnotherType> CollectionB {get; set;} 
}

public class DerivedEntityB : AbstractEntity
{
    public string Name {get; set;}
}

The relationships of above models are like this:

 RootEntity ---> ICollection<AbstractEntity>
                                 ┗━━ DerivedEntityA ---> ICollection<AnotherType>
                                 ┗━━ DerivedEntityB
 --->    has a
┗━━  derived from

Now I want to update a RootEntity entity named rootEntity by using GraphDiff:

 context.UpdateGraph(rootEntity, map => map
             .OwnedCollection(r => r.CollectionA, with => with
                 .OwnedCollection(de => de.CollectionB)  // this doesn't work because 'de' doesn't have 'CollectionB'
                 )
     );

So how can I update it properly?

2
  • Caveat: I've never used GraphDiff and I don't know how it works, but I found your question curious. I had a few ideas/comments. Is CollectionA guaranteed to only have entities of type DerivedEntityA? If not, I suspect GraphDiff might not be able to deal with that. If it does, could you do something like .OwnedCollection<RootEntity,DerivedEntityA>(r => r.CollectionA.OfType<DerivedEntityA>().ToList() to filter/cast your collection to the derived type? Commented Dec 6, 2014 at 9:56
  • @daspek Thanks for your comment. CollectionA can have both entities of DerivedEntityA and B, that's why I can't use OwnedCollection method directly. Commented Dec 8, 2014 at 5:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.