RIA 服务:枚举已删除的实体

发布于 2024-10-19 21:15:19 字数 687 浏览 4 评论 0原文

我的 RIA 服务上下文类有一个实体集 TaskToOperationAssociations,其中包含任务到操作关联的列表。

有没有办法“找到”已从集合中删除的关联实体?我可以看到上下文在其私有字段中引用了已删除的关联(显然需要跟踪它以便可以提交删除操作)。

这是一个例子...

如果我有任务“A”(Id=T1)与操作 X、Y 和 Z(ID 为 O1、O2 和 O3)关联,而任务 B(Id=T2)与操作关联相同的操作,则集合将包含 3 个 TaskToOperationAssociations,如下所示...

  1. 关联 A1,TaskId = T1,OperationID = 1
  2. 关联 A2,TaskId = T1,OperationID = 2
  3. 关联 A3,TaskId = T1,OperationID = 3
  4. 关联 A4,TaskId = T2,OperationID = 1
  5. 关联 A5,TaskId = T2,OperationID = 2
  6. 关联 A6,TaskId = T2,OperationID = 3

我删除关联 A1 并捕获 TaskToOperationAssociations 的属性更改事件。在事件处理程序中,我想查明任务 T1 的任何关联是否已更改,以便我可以在 UI 上启用保存按钮。

希望这是有道理的。 谢谢 本

My RIA service context class has an entity set TaskToOperationAssociations which contains a list of Task to Operation associations.

Is there a way to "find" an association entity which has been removed from the collection? I can see that the context has a reference to the removed Association in it's private fields (it obviously needs to keep track of it so the delete operation can be submitted).

Here's an example...

If I have Task "A" (with Id=T1) which is associated to Operation X, Y and Z (with id's O1,O2 and O3) and task B (with Id=T2) is associated with the same operations then the collection will contain 3 TaskToOperationAssociations as follows...

  1. Association A1, TaskId = T1, OperationID = 1
  2. Association A2, TaskId = T1, OperationID = 2
  3. Association A3, TaskId = T1, OperationID = 3
  4. Association A4, TaskId = T2, OperationID = 1
  5. Association A5, TaskId = T2, OperationID = 2
  6. Association A6, TaskId = T2, OperationID = 3

I remove association A1 and catch the property change event of the TaskToOperationAssociations. In the event handler I want to find out if any of the associations for Task T1 have changed so I can enable a save button on the UI.

Hope this makes sense.
Thanks
Ben

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你穿错了嫁妆 2024-10-26 21:15:19

您可以枚举ChangeSets,ChangeSet将包含提交之前的所有内容。在服务器端,您可以拦截 OnSaveChanges 并枚举 ChangeSet。

对于现有的关联更改,大多数更改集将包含外键的更改。您当前上下文的实体容器将包含尚未提交的变更集。

You can enumerate ChangeSets, ChangeSet will contain everything before it was submitted. On server side, you can intercept OnSaveChanges and also enumerate ChangeSet.

For existing association changes, mostly changeset will contain change of Foreign Key. Your current Context's Entity Container will contain ChangeSets that are not submitted yet.

梦境 2024-10-26 21:15:19

也许这可以帮助您

var deleted = Context.EntityContainer.GetChanges().RemovedEntities
    .Where(re => re is TaskToOperationAssociations && ((TaskToOperationAssociations)re.GetOriginal()).TaskId == T1.Id)
    .Select(re => (TaskToOperationAssociations)re);

,或者只是

var hasDeleted = Context.EntityContainer.GetChanges().RemovedEntities
    .Any(re => re is TaskToOperationAssociations && ((TaskToOperationAssociations)re.GetOriginal()).TaskId == T1.Id)

找出 T1 是否有任何已删除的关联

foreach (var assoc in deleted)
{
   Context.TaskToOperationAssociations.Add(assoc);
   ((IRevertibleChangeTracking)assoc).RejectChanges();
   ((IRevertibleChangeTracking)T1).RejectChanges();
}

您可以完全撤消删除(如果您尚未提交更改)

Maybe this can help you

var deleted = Context.EntityContainer.GetChanges().RemovedEntities
    .Where(re => re is TaskToOperationAssociations && ((TaskToOperationAssociations)re.GetOriginal()).TaskId == T1.Id)
    .Select(re => (TaskToOperationAssociations)re);

or just

var hasDeleted = Context.EntityContainer.GetChanges().RemovedEntities
    .Any(re => re is TaskToOperationAssociations && ((TaskToOperationAssociations)re.GetOriginal()).TaskId == T1.Id)

to find out if there are any deleted associations for T1

with

foreach (var assoc in deleted)
{
   Context.TaskToOperationAssociations.Add(assoc);
   ((IRevertibleChangeTracking)assoc).RejectChanges();
   ((IRevertibleChangeTracking)T1).RejectChanges();
}

you can completely undo the deletion (if you have not committed your changes yet)

紫﹏色ふ单纯 2024-10-26 21:15:19

仅使用上下文无法做到这一点。我通过包装上下文并手动跟踪删除来修复它。

There is no way to do this using only the context. I fixed it by wrapping the context and tracking deletions manually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文