0

我的 LINQ 查询有问题。每次运行时我都会收到此错误:

“S00117372_FOOP202_CA2.Order_Detail”的成员访问“System.Decimal UnitPrice”在“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
4

0 回答 0