LINQ错误 - 不支持方法'Sum'

RTR*_*zzz 4 c# linq linq-to-entities

我正在关注linq -

var quantity = (from p in context.StoreInventory
                         where p.BookId== BookId
                                && p.StoreAddress == StoreAddress
                         select p).Sum(i => i.Quantity);
Run Code Online (Sandbox Code Playgroud)

我收到错误 -

不支持"Sum"方法

任何人都可以告诉我原因和所需的变化.

Mar*_*zek 11

var quantity = (from p in context.StoreInventory
                         where p.BookId== BookId
                                && p.StoreAddress == StoreAddress
                         select p.Quantity).Sum();
Run Code Online (Sandbox Code Playgroud)

这应该工作 - 总和是在'Quality'列上执行的,这是使用select语句获取的.这是因为Sum(expression)LINQ to Entities不支持,但标准Sum()是.

整个工作应该由数据库完成,因此应用程序不会检索任何行 - 只需一个数字.