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,
- using
for...each
loop, loop on customers , modify field (imperative approach) - 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
Post a Comment