linq - DbContext with IQueryable entities write custom queries -


i stuck requirement past of couple days without progress.

our database layer handled through dbcontext repository , unit of work pattern. works on poko classes generate queries.

public virtual iqueryable<ent> all(params expression<func<ent, object>>[] includes)     {         iqueryable<ent> query = set;          query = addincludestoqry(query, includes);          return query;     }  protected dbset<ent> set     {         { return ctxt.set<ent>(); }     }  protected virtual iqueryable<ent> addincludestoqry(iqueryable<ent> query, params expression<func<ent, object>>[] includes)     {         expression<func<ent, object>>[] includestouse = d2l.nullorempty(includes)             ? defaultincludes             : includes;          if (d2l.nullorempty(includestouse)) return query;          foreach (var incl in includestouse)         {             query = query.include(incl);         }          return query;     } 

ent = poko model class

addincludestoqry = adds condition in clause.

this return entire table data (there table poko class name in database) filtering conditions.

however, want data little differently. ex, want restrict select list return deptname, count(employee) requires 2 columns in select list, , group deptname.

i not sure how can achieve using pattern can still iqueryable query.

can advise thoughts?

after grouping operation, schema of data you're working on changes (exactly in plain sql). surely can continue reference query iqueryable, not iqueryable<ent> (as suspect to).

in case iqueryable it's enough:

newqry = qry     .groupby(x => x.deptname)     .select(y => new { deptname = y.key, count = y.count() }); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -