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
Post a Comment