从集合中删除实体触发删除记录! [英] Remove entity from collection triggers delete of record!

查看:116
本文介绍了从集合中删除实体触发删除记录!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将以下代码关联到两个实体:

I the following code to associate two entities:

 


_dataContext.AddLink(CurrentVolunteer, "Groups", value);
CurrentVolunteer.Groups.Add(group);
group.Volunteers.Add(CurrentVolunteer);

推荐答案

如果CurrentVolunteer.Groups是DataServiceCollection< T>然后它是"按设计"。的DataServiceCollection< T>表现如果从中删除实体,它会将实体标记为已删除。在某些情况下,这是人们想要的,在某些情况下,
不是。您可以通过在DataServiceCollection< T>的构造函数中提供自定义处理方法来覆盖此行为。 - (例如,这个构造函数
http://msdn.microsoft.com/en-us/库/ ee652860.aspx )。如果你传递自己的Func for collectionChangedCallback,那么你可以在那里做你想做的事。所以你可以改变行为,而不是
标记要删除的实体你不这样做。请注意,如果指定Func,则DataServiceCollection将不会执行它所执行的操作,并且您可以将报告的更改传播到上下文(通过调用AddObject,DeleteObject以及
on)。

If the CurrentVolunteer.Groups is a DataServiceCollection<T> then it's "by design". DataServiceCollection<T> behaves such that if you remove entity from it, it will mark the entity as deleted. In some cases that's what people want, in some cases it's not. You can override this behavior by providing custom handling methods in the constructor of DataServiceCollection<T> - (for example this constructor http://msdn.microsoft.com/en-us/library/ee652860.aspx). If you pass in your own Func for collectionChangedCallback you get to do what you want there. So you can change the behavior and instead of marking the entity for deletion you don't do that. Note that if you specify the Func, the DataServiceCollection will not perform what it does and it's up to you to propagate the reported change to the context (via calls to AddObject, DeleteObject and so on).

谢谢,


这篇关于从集合中删除实体触发删除记录!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆