GraphDiff:" Cascading"拥有的收藏

时间:2015-08-13 00:29:55

标签: expression-trees graphdiff

我试图使用GraphDiff(NuGet中的最新版本)来处理我认为不是非常困难的实体模型。考虑这样的模型:

class A 
{
    public virtual ICollection<B> Bs { get; set; }
}

class B
{
    public virtual ICollection<C> Cs { get; set; }
}

如果我要更新A的实例(称之为 aEntity ),我可以这样做:

context.UpdateGraph(aEntity, map => 
    map.OwnedCollection(a => a.Bs, withB => 
        withB.OwnedCollection(b => b.Cs)))

现在,我有时也喜欢独立更新B。

context.UpdateGraph(bEntity, map => map.OwnedCollection(b => b.Cs));

所以我想我可以&#34;级联&#34;引入财产的变化,如下:

class BMapper {
    Expression<Func<IUpdateConfiguration<B>, object>> MappingExpression 
    {
        get 
        {
            return map => map.OwnedCollection(b => b.Cs);
        }
    }
}

...然后在两种情况下都使用它:

// Update an A and any of its B's
context.UpdateGraph(aEntity, map =>
    map.OwnedCollection(a => a.Bs, (new BMapper()).MappingExpression))

// Update a B by itself
context.UpdateGraph(bEntity, (new BMapper()).MappingExpression);

更新B本身可以正常工作,但更新A会在表达式中落下:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 
    'string' does not contain a definition for 'Body'

有没有办法在GraphDiff中共享映射?

0 个答案:

没有答案