c# - How to write the following query in LINQ -
i have sql query , convert linq
select cast([date] date), count([id]) 'amount of systems' [demodb].[dbo].[servers] [serverid] in ('serverx') , [type] = 'complete' group cast([date] date) order cast([date] date) this return result follows

what have tried
//fromdp , todp names of datepicker's var query = (this.db.servers .where(x => x.date >= fromdp.selecteddate.value && x.date <= todp.selecteddate.value)); var query_success = query.count(p => p.type == "complete" && (p.serverid == "serverx")); and have result count on whole ( example, if select from april 1st april 15th , result sum of "complete"), need count each day in selected range. result bind column chart. how proceed ?
if understood correctly author wants use date without time. ef can use method entityfunctions.truncatetime trimming time portion. build on @steaks answer:
db.servers.where(s => s.serverid == "serverx" && s.type == "complete") .groupby(s => entityfunctions.truncatetime(s.date)) .orderby(s => s.key) .select(g => new {date = g.key, amountofsystems = g.count()});
Comments
Post a Comment