entity framework - Lambda Grouping to Generic Repository EF with order by C# -


i have query repository base, , here have generic implementation return records & aren't paged, , need implement grouping in generic death of system.

a pagedresult object returned of specific type:

public class pagedresult<t> : pageddata {     public ilist<t> results { get; set; } } 

pageddata object has random return fields...

the method of doom in question following:

public virtual pagedresult<tentity> getpagegrouped(int pageindex, int pagesize, func<iqueryable<tentity>, iorderedqueryable<tentity>> orderby,          expression<igrouping<object,tentity>> groupby, expression<func<tentity, bool>> filter = null, params expression<func<tentity, object>>[] navs)     {         iqueryable<tentity> query = this.context.set<tentity>();          if (filter != null)         {             query = query.where(filter);         }          foreach (var nav in navs)         {             query = query.include(nav);         }          return new pagedresult<tentity>         {             results = groupby(query).orderby(query).skip((pageindex) * pagesize).take(pagesize).tolist(),             rowcount = query.count(),             currentpage = pageindex         };     } 

and use it, want call like:

var list = _repo.getpage(page, pagesize, t => t.orderby(p => p.clientid), t => t.groupby(z => new { z.field1, z.field2, z.field3 })); 

my problem maybe not understanding igrouping, cannot query that's being built work , dying.

any assistance awesome!

edit if write normal linq expression similar to:

return context.table1s.groupby(i => i.policy)                   .select(g => g.first())                   .orderby(i => i.policy)                   .skip(endingrecord).take(page)                   .tolist(); 

you try

expression<igrouping<object,tentity>>[] groupby 

this allows send multiple parameter repository expression

public async task<ienumerable<t>> getpagedasync(        func<iqueryable<t>,        iorderedqueryable<t>> orderby,        expression<func<t, bool>> filter = null,        int? page = 0,        int? pagesize = null, params expression<func<t, object>>[] includes,        expression<igrouping<object,tentity>>[] groupby)     {         iqueryable<t> query = dbset;            if (filter != null)         {             query = query.where(filter);         }          //includes         if (includes != null && includes.any())         {             query = includes.aggregate(query,                       (current, include) => current.include(include));         }          if (orderby != null)             query = orderby(query);         else             throw new argumentnullexception("the order necessary in pagining");             if (page != null && page > 0)         {             //(0-1)             if (pagesize == null) throw new argumentexception("the take paremeter supplied null, should included when skip used");             query = query.skip(((int)page - 1) * (int)pagesize);         }          if (pagesize != null)         {             query = query.take((int)pagesize);         }          return await query.tolistasync();     } 

i use this

.myrepository .getpagedasync(h => h.orderby(l => l.rating)  ,g => g.groupid == _categoryid, skip, take); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -