c# - How to cast back an object with a linq query inside it with more than 1 entity? -


this question has answer here:

i have following scenario. 1 query join statment:

public object getmgm(int meb_id) {     var unitofwork = new dal.implementations.entity_framework.unitofwork<dbgmentities>();      var queryroles =  in unitofwork._ctx.membrosmgm                           join b in unitofwork._ctx.membros on a.mgm_pai equals b.meb_id                           a.mgm_filho == meb_id                           select new { b.meb_nome, b.meb_id, a.mgm_familiar };      return queryroles; } 

queryroles running inside thread. so, have return object. cannot find way cast , { b.meb_nome, b.meb_id, a.mgm_familiar } of select. tried following code 1 entity set on return , works fine, if have more 1 entity on same linq query don't know how cast back:

//this 1 works fine if have 1 entity set (dal.membroresponsavel) var querymembroresponsaveis = ((ienumerable)smartthreadpool.queueworkitem(x => editmeb.getmembroresponsavel(currentid)).result).cast<dal.membroresponsavel>().tolist(); 

thanks.

for having same problem returning anonymous type created class gets return values:

public class membergetamember {     public int meb_id {get;set;}     public string meb_nome { get; set;}     public bool? mgm_familiar { get; set; } } 

then can cast on return:

foreach (var x in queryroles)             list.add(new membergetamember { meb_id = x.meb_id, meb_nome = x.meb_nome, mgm_familiar = x.mgm_familiar });          return list; 

this question helped me how figure out

how return query results method uses linq sql

thanks everyone.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

jquery - How can I dynamically add a browser tab? -