In my new project, I`m writing a lot of linq. And I have a lot of linq queries like this:
...
group new {A, B} by new {....}
into g
// Calculate select claw
let SumVal1 = g.Sum(x => x.A.Value1 * func(x.A, x.B)) / g.Sum(x => func(x.A, x.B))
let SumVal2 = g.Sum(x => x.A.Value2 * func(x.A, x.B)) / g.Sum(x => func(x.A, x.B))
let SumVal3 = g.Sum(x => x.A.Value3 * func(x.A, x.B)) / g.Sum(x => func(x.A, x.B))
....
// Here could be some calculation, that are not patterned, like:
let NotPatternedSum1 = g.Sum(x => x.A.Duration)
...
select new {SumVal1, SumVal2, SumVal3, ..., NotPatternedSum, ...}
How can I simplify this? I have many queries with this pattern (Sum(A*func)/Sum(func)) - how can I introduce this to a single method or delegate?
Maybe you've seen some advises for a designing big linq queries? My code is consists of 95% linq (I`m moving db logic to a client). Pls, give me some tips, maybe non trivial =)
And I want to avoid using non-anonymous types