c# - Declaring an empty Queryable? -


how declare such variable?

            var rdata = nc in ctx.newsletter_clients                         join ni in ctx.newsletter_indices on nc.index_num                                                            equals ni.index_num                         select new                         {                             clientid = nc.client_id,                             email = nc.client_email_address,                             index = nc.index_num,                             mainclass = ni.main_class,                             subclass = ni.sub_class,                             app1 = ni.value_1,                             app2 = ni.value_2,                             app3 = ni.value_3,                             app4 = ni.value_4                         };          // need declare on variable named fdata under function scope,         // can later use it:          var fdata = ...; //what declare here?          if(x)             fdata = fdata.concat(rdata.where(u => ...));         if(y)             fdata = fdata.concat(rdata.where(u => ...));         // etc 

iqueryable<type of p> fdata = null; 

if want use query later (iow after if):

var fdata = enumerable.empty<type of p>().asqueryable(); 

update:

now using anonymous types:

iqueryable<t> restofmethod<t>(iqueryable<t> rdata) {   var fdata = enumerable.empty<t>().asqueryable(); // or = rdata;    if(x)     fdata = fdata.concat(rdata.where(u => ...));   if(y)     fdata = fdata.concat(rdata.where(u => ...));    return fdata; }  // original code location var rdata = query; var fdata = restofmethod(rdata); 

update 2:

as pointed out, above not work, predicate of where not know type. refactor more include predicates in parameters, example:

iqueryable<t> restofmethod<t>(iqueryable<t> rdata,    expression<func<t,bool>> pred1,   expression<func<t,bool>> pred2)  { ... } 

update 3: (perhaps hacky)

var fdata = rdata.take(0); // should cheap.  

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -