我的LINQ查询存在问题。每次运行时我都会收到此错误:
成员访问'System.Decimal UnitPrice' 'S00117372_FOOP202_CA2.Order_Detail'在类型上不合法 “S00117372_FOOP202_CA2.Order。
我无法找出问题所在,但我觉得它很简单。
var t3 = from o in db.Orders
join OrderID in db.Order_Details
on o.OrderID equals OrderID.OrderID
into g
group o by new { o.CustomerID, g }
into od
select new
{
od.Key,
Column1 = (System.Decimal?)od.Key.g.Sum(p => p.UnitPrice * p.Quantity )
};
Tab3.DataContext = t3;
这是SQL中代码的工作版本:
use Northwind
go
select CustomerID, sum(UnitPrice * Quantity)
from dbo.[Order Details]
join Orders
on dbo.[Order Details].OrderID = dbo.Orders.OrderID
group by dbo.Orders.CustomerID