.net - Optimizing Linq Query -


i attaching simple linq query. want figure out if there better , efficient way of pulling these 3 fields (field1 , field2, field3) mentioned in linq query below.

from currentcons in activeconnections join accounts in accounts on currentcons.new_accountid equals accounts.accountid                                      let field1 =(from holder in mapholders         join entity in entities on stringmap.objecttypecode equals   entity.objecttypecode         entity.name == "new_connection"         holder.attributename == "new_data"         holder.attributevalue ==  currentcons.new_data_val         select holder.value)  let field2=(from holder in mapholders         join entity in entities on stringmap.objecttypecode equals entity.objecttypecode         entity.name == "new_connection"         holder.attributename == "new_type"         holder.attributevalue == currentcons.new_type         select holder.value) let field3=(from holder in mapholders         join entity in entities on stringmap.objecttypecode equals entity.objecttypecode         entity.name == "new_connection"         holder.attributename == "new_entrypoint"         holder.attributevalue == currentcons.new_entrypoint         select holder.value)    currentcons.modifiedon >= convert.todatetime("1/1/2011")    currentcons.modifiedon <= convert.todatetime("5/5/2012")    select new     {       conid = currentcons.connectionid,       conname = currentcons.name,       typeid = currentcons.type,       accountid = currentcons.accountid,       oid = currentcons.ownerid,       bandwidthid = currentcons.bandwidth,       entrypointid = currentcons.entrypoint,       cap = field1 ,       dir=field2,       ep=field3,       modifiedon = currentcons.modifiedon     } 

i know other way put directly in select block . whats efficient way ?

any pointers appreciated.

thanks.

var fromdate =  new datetime(2011,1,1); var todateplusoneday = new datetime(2012,5,5).adddays(1); // add 1 day ensure   var result = currentcons in activeconnections             join accounts in accounts on currentcons.new_accountid equals accounts.accountid                                                  currentcons.modifiedon >= fromdate             currentcons.modifiedon < todateplusoneday              holder in mapholders             (holder.attributename == "new_data" && holder.attributevalue == currentcons.new_data_val) || (holder.attributename == "new_type" && holder.attributevalue == currentcons.new_type) || (holder.attributename == "new_entrypoint" && holder.attributevalue == currentcons.new_entrypoint)             select new              {               conid = currentcons.connectionid,               conname = currentcons.name,               typeid = currentcons.type,               accountid = currentcons.accountid,               oid = currentcons.ownerid,               bandwidthid = currentcons.bandwidth,               entrypointid = currentcons.entrypoint,               modifiedon = currentcons.modifiedon,               cap = (holder.attributevalue == currentcons.new_data_val) ? holder.value : null,               dir = (holder.attributevalue == currentcons.new_type) ? holder.value : null,               ep = (holder.attributevalue == currentcons.new_entrypoint) ? holder.value : null                           }    

i removed following since it's not used in result

join entity in entities on stringmap.objecttypecode equals entity.objecttypecode         entity.name == "new_connection" 

also please check if cap/dir/ep nullable


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -