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));
したがって、次のように、プロパティを導入することで変更を「カスケード」できると考えました。
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 でマッピングを共有する方法はありますか?