c# - How to modify only one or two field(s) in LINQ projections? -


i have linq query:

list<customers> customers = customermanager.getcustomers();  return customers.select(i => new customer {     fullname = i.fullname,     birthday = i.birthday,      score = i.score,     // here, i've got more fields fill     isvip = determinevip(i.score) }).tolist(); 

in other words, want 1 or 2 fields of list of customers modified based on condition, in business method. i've got 2 ways this,

  1. using for...each loop, loop on customers , modify field (imperative approach)
  2. using linq projection (declarative approach)

is there technique used in linq query, modify 1 property in projection? example, like:

return customers.select(i => new customer {     result = // telling linq fill other properties     isvip = determinevip(i.score) // modifying 1 property }).tolist(); 

you can use

return customers.select(i => {     i.isvip = determinevip(i.score);     return i; }).tolist(); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -