How to update an entity with a collection of abstract types by using GraphDiff?

221 Views Asked by At

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?

0

There are 0 best solutions below