首页 新闻 会员 周边 捐助

LINQ TO SQL子查询的问题

0
[已解决问题] 解决于 2009-06-22 16:41
DbNorthwind northwind = new DbNorthwind();
Console.WriteLine(
"查询订单数超过5的顾客信息:");
var result
=
from c
in northwind.Customers
where
(
from o
in northwind.Orders
group o by o.CustomerId into o
where o.Count() > 5
select o.Key
).Contains(c.CustomerID)
select c;
Console.WriteLine(northwind.GetCommand(result).CommandText);
Console.WriteLine();

提示错误:
错误 1 无法从用法中推导出方法“System.Linq.Enumerable.Contains<TSource>(System.Collections.Generic.IEnumerable<TSource>, TSource)”的类型实参。请尝试显式指定类型实参。 G:\TestApp\Linq\ToSqlStudy\Part04\SubQuery.cs 20 6 Part04
没有明天的主页 没有明天 | 初学一级 | 园豆:190
提问于:2009-06-18 12:49
< >
分享
最佳答案
0
var result =
from c
in northwind.Customers
where
(
from o
in northwind.Orders
group o by o.CustomerId into o
where o.Count() > 5 and o.CustomerId==c. CustomerID
select o.Key
)
select c;
试试看~
斯克迪亚 | 老鸟四级 |园豆:4124 | 2009-06-18 13:21
其他回答(1)
0

可能是你的o.CustomerId类型不对,我测试了,可以的。

SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax]
FROM [Customers] AS [t0]
WHERE EXISTS(
SELECT NULL AS [EMPTY]
FROM (
SELECT [t1].[CustomerID]
FROM [Orders] AS [t1]
GROUP BY [t1].[CustomerID]
)
AS [t2]
WHERE ([t2].[CustomerID] = [t0].[CustomerID]) AND (((
SELECT COUNT(*)
FROM [Orders] AS [t3]
WHERE [t2].[CustomerID] = [t3].[CustomerID]
))
> @p0)
)

麦舒 | 园豆:452 (菜鸟二级) | 2009-06-18 22:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册