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

enter image description here

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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -