c# - merge properties from two lists -


i have code:

   ienumerable<carresultsviewmodel> priceresults = price.select(p => new carresultsviewmodel                     {                         priceperday = p.priceperday,                         priceperdaydelayed = p.priceperdaydelayed,                         totalprice = (double)p.total_price                     }).tolist();     ienumerable<carresultsviewmodel> results = car.select(c => new carresultsviewmodel                     {                         creationyear = c.creationyear,                         manufacturername = c.manufacturername,                         modelname = c.modelname,                         gear = c.gear,                         currentkm = c.currentkm,                         picture = c.picture,                         startdate = model.startdate,                         returndate = model.returndate                     }).tolist(); 

i implement 3 properties in priceresults results list. there elegant way that?

the commentors correct, can use join function of linq "merge" these 2 lists together, such as:

            var carresults = (from pr in priceresults             join r in results                 on pr.carid equals r.carid             select new carresultsviewmodel             {                 carid = pr.carid,                 priceperday = pr.priceperdaydelayed,                 manufacturername = r.manufacturername,                 etc...             }).tolist(); 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -