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?
.OwnedCollection<RootEntity,DerivedEntityA>(r => r.CollectionA.OfType<DerivedEntityA>().ToList()to filter/cast your collection to the derived type?OwnedCollectionmethod directly.