asp.net mvc - Alternative to using String.Join in Linq query -


i trying use entity framework in asp mvc 3 site bind linq query gridview datasource. since need pull information secondary table 2 of fields getting error

linq entities not recognize method 'system.string join(system.string, system.collections.generic.ienumerable'1[system.string])' method, , method cannot translated store expression.

i able without creating dedicated view model. there alternative using string.join inside linq query?

var grid = new system.web.ui.webcontrols.gridview();  //join in db.banklistagentid on b.id equals a.bankid var banks = b in db.banklistmaster     b.status.equals("a")     select new     {         bankname = b.bankname,         epurl = b.epurl.trim(),         associatedtpmbd = b.associatedtpmbd,         fixedstats = string.join("|", in db.banklistagentid                                       a.bankid == b.id &&                                       a.fixedorvariable.equals("f")                                       select a.agentid.tostring()),         variablestats = string.join("|", in db.banklistagentid                                          a.bankid == b.id &&                                          a.fixedorvariable.equals("v")                                          select a.agentid.tostring()),         specialnotes = b.specialnotes,     };  grid.datasource = banks.tolist(); grid.databind(); 

if you're not overly worried performance (since has subqueries, may generate n+1 queries database, , if database rows large, may fetch un-necessary data), simplest fix add asenumerable() string.join on web/application side;

var banks = (from b in db.banklistmaster               b.status.equals("a") select b)             .asenumerable()              .select(x => new {...}) 

at point of call asenumerable(), rest of linq query done on application side instead of database side, you're free use operators need job done. of course, before you'll want filter result as possible.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -