0

给定一个包含子集合的父级,归因于:

[Include, Composition]
public virtual ICollection<FieldValue> FieldValues {get;set;}

并做一个负载:

Context.Load(Context.GetQuery(),LoadBehavior.RefreshCurrent,true);

我看到其他用户或后台进程删除的 FieldValues 不会从客户端上下文中删除。我可以看到这可能是设计使然,但我该如何解决这个问题?有没有办法插入加载过程来处理已删除的项目?

加载回调发生得太晚了,看起来 - 一切都已经合并了,没有什么可比较的。

4

1 回答 1

1

弄清楚了。给定一个父类 Root,这是运行负载的方式:

var originalValues = Context.EntityContainer
    .GetEntitySet<FieldValue>()
    .ToList(); // <-- make the pre-load copy of the child entities

Context.Load(Context.GetQuery(),
    LoadBehavior.RefreshCurrent,
    (LoadOperation<Root> o) =>
    {
        (from v in originalValues
        join nv in o.AllEntities.OfType<FieldValue>() on v equals nv into g
        from existing in g.DefaultIfEmpty()
        where existing == null
        select v)
        .ToList()
        .ForEach(Context.EntityContainer.GetEntitySet<FieldValue>().Detach);
    },
    null);

注意:FieldValue 实现 IEquatable<>,如果您的孩子没有,请使用 PK

于 2012-06-25T19:10:29.480 回答