c# - How to create query of queries using LINQ? -


i'm trying convert query of queries used in coldfusion linq , c#. data come data files, rather database.

i converted first query, have no clue

  1. how use query second query.

  2. how include count(pdate) daycount in second query.

below code using query of queries in coldfusion:

first query <cfquery name="qsorted" dbtype = "query">     select oa, cd,pdate,     dataquery      group cd,oa,pdate,        </cfquery>  second query <cfquery name="qdaycount" dbtype = "query">     select oa, cd, count(pdate) daycount      qsorted   // qsorted first query.                 group      oa, cd     order      oa, cd </cfquery> 

here's first converted linq query, , works fine:

var rows = alldata.selectmany(u => u._rows.select(t => new {             oa = t[4],   cd = t[5],   pdate = t[0]               })) .groupby(x => new { x.cd, x.oa, x.pdate  }) .select(g => new {   g.key.oa,   g.key.cd,   g.key.pdate  }) .tolist(); 

here's pseudo-code second linq query, need assistance:

var rowsdaycount  = rows //is correct? if not, how it? .groupby(x => new { x.oa, x.pdate, x.cd, }) .select(g => new {   g.key.oa,   g.key.cd,   g.key.pdate,//pdate should pdate.distinct().count() asdaycount       // see daycount in cfquery name="qdaycount" above. }) .orderby(u => u.oa) .thenby(u => u.cd)  .tolist(); 

your second query origionally wasn't grouping on pdate, translation is. that's wrong. if want count number of pdates each oa/cd pair, need not group on pdate. once you've made change, can modify select pull out of pdate values group, , count distinct values.

.groupby(x => new { x.oa, x.cd, }) .select(g => new {     g.key.oa,     g.key.cd,     daycount = g.select(item => item.pdate).distinct().count(), }) 

Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

basic authentication with http post params android -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -