halera
halera

Reputation: 165

Linq to Enity complex query

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?

Upvotes: 1

Views: 104

Answers (1)

Xilmiki
Xilmiki

Reputation: 1502

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");

Upvotes: 1

Related Questions