在这种情况下:

var allCustomers = from c in customers select c;
var oldCustomers = from o in allCustomers where o.age > 70 select o;
.

子句达到数据库?

有帮助吗?

解决方案

我觉得你的意思是:

var oldCustomers = from o in allCustomers where o.age > 70 select o;
.

是,它将到达数据库。

尝试使用linqpad查看生成的SQL代码。这是一个例子:

我有一个具有字段的世代odicetagcode表:

Actor

代码:

var x = from c in Actors where c.Name.Contains("a") select c;
var y = from c in x where c.Age > 0 select c;
.

被翻译为:

-- Region Parameters
DECLARE @p0 Int = 0
DECLARE @p1 NVarChar(3) = '%a%'
-- EndRegion
SELECT [t0].[Id], [t0].[Name], [t0].[Age]
FROM [Actor] AS [t0]
WHERE ([t0].[Age] > @p0) AND ([t0].[Name] LIKE @p1)
.

所以你可以看到它是如何在一个只有一个查询中混合的。

记住,iEnumerables是懒惰的,所以你必须知道他们的元素(因为你迭代它们,或者因为你做生意icetagcode看多少项等),它不会执行任何查询/操作。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top