c# - EntityFramework Generic Repository, multiple include? -


i trying change generic retrieve method generic repository. want instead pass string includeproperties, pass this: params expression<func<tentity, object>>[] includeproperties = null thing when call method:

public virtual ienumerable<tentity> retrieve(expression<func<tentity, bool>> filter = null, params expression<func<tentity, object>>[] includeproperties = null) 

i want example: tentityexample.retrieve(filter: c=>c.id=id, includeproperties:c=> c.propertynav1, e=> e.propertynav1.propertynav3, e=> e.prop4)

or if dont need navigation properties tentityexample.retrieve(filter: c=>c.id=id)

but dont know why includeproperties: not working, not accepted, know why, or if doing wrong. want possibility dont pass includeproperties or pass specifying includeproperties:

public virtual ienumerable<tentity> retrieve(expression<func<tentity, bool>> filter = null, string includeproperties = "")             {                 iqueryable<tentity> query = _dbset;                  if (filter != null)                 {                     query = query.where(filter);                 }                  if (!string.isnullorempty(includeproperties))                 {                     foreach (var includeproperty in includeproperties.split                         (new char[] { ',' }, stringsplitoptions.removeemptyentries))                     {                         query = query.include(includeproperty);                     }                 }                 return query.tolist();             } 

i similar, instead use expressions eagerly load. maybe help:

    public tentity item(expression<func<tentity, bool>> wherepredicate, params expression<func<tentity, object>>[] includeproperties)     {         foreach (var property in includeproperties)         {             _dbset.include(property);         }         return _dbset.where(wherepredicate).firstordefault();     } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -