Linq to Entity复杂查询

时间:2011-09-10 17:50:24

标签: entity-framework entity-framework-4

我的实体包含Id, Price

我想构建linq to entiy查询,count行数,总结Price,然后从count减去Price并将结果相乘one hounded

(Count(*) - SUM(Price))*100

是否可以使用实体框架4.0创建这样的单个查询?

1 个答案:

答案 0 :(得分:1)

这应该有效

var ris = (from p in dc.Products  group p by p into a  select   (a.Count() - a.Sum(z => z.UnitPrice)) * 100).First();

 var ris= dc.ExecuteStoreQuery<double>("select (Count(*) - SUM(Price))*100 from mytable");