开发者

Linq to Enity complex query

开发者 https://www.devze.com 2023-04-03 19:35 出处:网络
I have entity which开发者_开发技巧 contains Id, Price columns I want to build linq to entiy query which would count the number of rows, summarize the Price and than subtract count from Price and mult

I have entity which开发者_开发技巧 contains Id, Price columns

I want to build linq to entiy query which would count the number of rows, summarize the Price and than subtract count from Price and multiplied the result by one hounded.

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

Is it possible to create such single query with entity framework 4.0?


this should work

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

or

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

精彩评论

暂无评论...
验证码 换一张
取 消