c# - Return IQueryable<T> from my method? Is it the right way to do it? -


i spent time find how return iqueryable method... , i'm still wondering if right way it.

here repository class:

public class carrepository : icarrepository {     // fake entities     private ilist<car> _entities = new list<car>()     {         new car() { brand = "lamborghini", name = "huracán"},         new car() { brand = "bmw", name = "x6" }     };      // allows deferred execution/further refinement     public iqueryable<car> findbyqueryable(expression<func<car, bool>> predicate)     {         var query = _entities.where(predicate.compile()).asqueryable();         return query;     }      // returning ilist or ienumerable     public ilist<car> findby(expression<func<car, bool>> predicate)     {         return _entities.where(predicate.compile()).tolist();     } } 

at first thought should work, not compiling:

    public iqueryable<car> findbyqueryable(expression<func<car, bool>> predicate)     {         var query = _entities.where(predicate);         return query;     } 

am right predicate.compile() , .asqueryable?

thanks help! bastien

as stand makes no sense. if want use queryable methods remote queries database must use expression trees. using compile converts tree delegate destroys opportunity.

_entities must iqueryable<t> in order target queryable methods.

asqueryable code smell indicates mistakes describe above. fake queryable. in-memory (except if source iqueryable; cast).


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -