c# - Why is using tolist() not a good approach here? -


this not approach here...! can why?

var dbc= new schoolcontext(); var a=dbc.menus.tolist().select(x=> new {                              x.type.name,                              listofchildmenus = x.childmenu.select(cm=>cm.name),                              listofsettings = x.settings.selectmany(set=>set.role)                                          }); 

because when call .tolist() or .firstordefault() , on (when enumerate), query executed.

so when dbc.menus.tolist() bring in memory database menus, , didn't want that.

you want bring in memory select ( list of child menus , list of settings ).

relevant furter reading : http://www.codeproject.com/articles/652556/can-you-explain-lazy-loading - using lazy loading

and if want add filter iqueryable may read difference between ienumerable, iqueryable http://blog.micic.ch/net/iqueryable-vs-ienumerable-vs-ihaveheadache

and dinamic filtering https://codereview.stackexchange.com/questions/3560/is-there-a-better-way-to-do-dynamic-filtering-and-sorting-with-entity-framework


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -