c# - Linq Sum inline -


is possible linke this?

entity (with 3 properties)
---> int a
---> int b
---> int c

from record in dbset select new entity   {       = record.a       b = record.b      c = * b   } 

when using object initialization syntax, can assign properties field available @ construction time. so, have 2 options if want c computed off of a , b. can read properties off of record:

from record in dbset select new entity   {       = record.a       b = record.b      c = record.a * record.b   } 

more complicated situations might make untenable repeat definitions of a , b in way. example, repeating long definition how properties computed might computationally expensive. harder read when similar code repeated. in cases might want have intermediary select class gathers relevant information before final select:

from record in dbset select new { = somecomplicatedfunction(record.a), b = somecomplicatedfunction(record.b) } info select new entity { = info.a, b = info.b, c = info.a * info.b } 

of course, if c computed off of a , b, make getter property, suggested @vc74


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -