为什么dataContext.GetChangeSet()。Deletes.Count()总是返回0? [英] Why is dataContext.GetChangeSet().Deletes.Count() always returning 0?
本文介绍了为什么dataContext.GetChangeSet()。Deletes.Count()总是返回0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这回事:
var customerIdsToDelete = new {1, 2, 3};
var dataContext = new DataContext();
var customersToDelete = (from c in data.Customers
where customerIdsToDelete.Contains(c.CustomerID)
select c);
data.Customers.DeleteAllOnSubmit(customersToDelete);
data.SubmitChanges();
var deletedCount = data.GetChangeSet().Deletes.Count();
即使当客户成功删除 deletedCount
将是0。
为什么呢?而这将是计数客户数的正确的方式
删除?
Why? And what would be the "correct" way of counting the number of customers
deleted?
推荐答案
由于您已提交的变化。一旦调用的SubmitChanges
已经取得了那么有没有删除,因此(正确地)返回计数为零。要获取删除(或者被删除)的项目数那就试试这个(即确定计数推动改变之前):
Because you've submitted the changes already. Once the call to SubmitChanges
has been made then there are no deletes, and therefore (correctly) a count of zero is returned. To get the number of items deleted (or, to be deleted) then try this (i.e. determining the count prior to pushing the changes):
...
var deletedCount = data.GetChangeSet().Deletes.Count();
data.SubmitChanges();
...
这篇关于为什么dataContext.GetChangeSet()。Deletes.Count()总是返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文