c# - Property Mapping with Reflection efficiency -


i have object populating via mapping , lookup woth reflection, here call

this.searchresults = (from in response.postings                               select new searchresponsemodel                               {                                   id = a.id,                                   timestampdate = a.timestampdate,                                   body = a.body,                                   title = a.heading,                                   status = a.status,                                   state = a.state,                                   language = a.language,                                   currency = a.currency,                                   categorygroup = a.category_group,                                   source = a.source,                                   externalid = a.external_id,                                   externalurl = a.external_url,                                   price = a.price,                                   location = populatelocation(a.location)                               }                               ).tolist(); 

and method mapping.

 private static list<locationlookupmodel> populatelocation(location location)     {         list<locationlookupmodel> alllocations = new list<locationlookupmodel>();         if (httpcontext.current.session["locationmodel"] == null)         {              httpcontext.current.session["locationmodel"] = alllocations = new locationmodel().locationlist;         }         else         {             alllocations = (list<locationlookupmodel>)httpcontext.current.session["locationmodel"];         }         list<locationlookupmodel> modellist = new list<locationlookupmodel>();          foreach (propertyinfo propertyinfo in location.gettype().getproperties())         {             var value = propertyinfo.getvalue(location);             if (value != null)             {                 locationlookupmodel model = (from in alllocations                                              a.code == propertyinfo.getvalue(location).tostring()                                              select a).firstordefault();                 if (model != null)                 {                     modellist.add(model);                 }             }         }          return modellist;     } } 

the issue run alllocations object has 70k records (it represents list of location lookup values countries, states, zipcodes, etc), , populating 100 instances of searchresponsemodel takes 20 seconds. far long ui call, , have not been able find way make faster. understand doing 3 nested loops (calling helper method each population, looping on reflected properties, , linq call on 70k records) there time efficiency issues, bit lost on tricks can use make process more efficient.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -