English 中文(简体)
我如何利用既定行动删除与收集观点模型相匹配的实体中的物体?
原标题:How can I use set operations to delete objects in an entitycollection that match a collection of view models?

Here is a very basic example of what I want to do. The code I have come up with seems quite verbose... ie looping through the collection, etc.

我正在使用一个电离层MVC电网,该电网将汇回一个被删除、插入和更新的视角模型。 观点模式与实体相似,但并非完全相同。

例如...... 我已:

Order.Lines. 线路是包含订单详细记录的实体收集(不动产)。 在我的控制人员使用我的最新行动中,有一份名单,删除了摘自名册上的数据。 我还询问了该数据库,并设有秩序实体,包括线索收集。

现在,我基本上要告诉它,删除“线索实体”的所有命令。

The way I have done it is something like:

foreach (var line in DeletedLines) {
   db.DeleteObject(Order.Lines.Where(l => l.Key == line.Key).SingleOrDefault())
}

我希望我能够利用“Interset()”来收集实体,删除并删除“Object”一词,但删除“Object”似乎只接受一个单一实体,而不是收集。

Perhaps the above is good enough.. but it seemed like there should be an easier method.

Thanks, BOb

最佳回答

删除中的项目是否附属于这一背景? 如果是,情况如何?

foreach (var line in DeletedLines) db.DeleteObject(line);

www.un.org/Depts/DGACM/index_spanish.htm 对第1号一般性意见的答复

奥基,我现在看。 你们能够使你的法典缩短一点,但不是:

foreach (var line in DeletedLines) {
   db.DeleteObject(Order.Lines.SingleOrDefault(l => l.Key == line.Key))
}

我不敢肯定,如果删除“目标”的话,就会放弃一个例外。 如果是的话,只要你确信该项目在其中,你就能够更好地使用单一系统:

foreach (var line in DeletedLines) {
   db.DeleteObject(Order.Lines.Single(l => l.Key == line.Key))
}
问题回答

如果你不想重新排列数据库,或者已经掌握了绘图表的PK值(或可以将这些数值列入客户要求),你可以使用Alex James的斜线之一来删除,而无需首先检索:

http://blogs.msdn.com/b/alexj/archive/2009/03/27/tip-9-deleting-an-object-without-retrieving-it.aspx





相关问题
LINQ to SQL and a running total on ordered results

I want to display a customer s accounting history in a DataGridView and I want to have a column that displays the running total for their balance. The old way I did this was by getting the data, ...

Can I do this with an IQueryable<T>?

is it possible to add an extension method to IQueryable<T> and then, for my Linq2Sql or EF or NHibernate or LinqToObjects, define it s functionality / how each repository will impliment this ...

AlphaNumeric ordering in SQL vs. LINQ and .NET

I encountered an interesting thing today that I have never noticed before. It appears that SQL and LINQ order AlphaNumeric strings differently. Data table contains rows: A G 6 P 1 D J 2 T Z 9 F 0 ...

If statement or Where extension with a For Each loop?

I was wondering which of the two code samples would be more efficient (or is the difference between the two negligible)? For Each apple in AppleController.GetRedApples().Where(Function(a) ...

Differences between LINQ to Objects and LINQ to SQL queries

I have been using LINQ to query my POCO objects for some time, but I have not yet tried LINQ to SQL. I assume that LINQ to SQL queries are somehow converted to equivalent SQL queries and, given this, ...

动态准则 询问

能否在业余时间建立LinqQuries。

热门标签