c# - Joining Collections and Assigning values -


i have 2 collections , want join them based on key attribute , assign 1 collection's values other. doing in following way

var joineddata =   collection_one in office.employees                 join collection_two in newoffice.employees                    on collection_1.officeid equals collection_two.officeid                select new { collection_one, collection_two};   // declare new collection   icollection<office.employees> updatedcollection = new list<office.employees>();  // assign new collection_two values collection_one foreach (var item in joineddata.tolist())             {                 item.collection_one.deleted = item.collection_two.deleted;                 updatedcollection .add(item.obp);             } 

this not producing right result. join producing more records should inner join. can spot issue ?

try left join using defaultifempty() :

    var updatedcollection =         (from collection_one in office.employees           collection_two in newoffice.employees.where(x => x.officeid == collection_one.officeid).defaultifempty()          collection_two == null          select new {               collection_one,               collection_two          }).select(x => {             x.collection_one.deleted = x.collection_two.deleted;             return x.obp;          }); 

but x.obp? maybe result should x.collection_one?


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -