I am working with a pretty large SQL view (50+ columns). To ensure i get the correct data i have to select a subset of the columns (4 or 5 columns) and group by that sub set. (otherwise i will have extra data returned). This means i am writing a lot queries, all very similar with very minor differences.
I currently run my queries like so
var result = this.UtilContext.MassiveView
.GroupBy(g => new
{
g.id,
g.Value1,
g.Value2,
g.Value3
}).Where(c => c.Key.id == SomeID)
.AsNoTracking()
.Select(x => new
{
id = x.Key.id,
Value1 = x.Key.Value1,
Value2 = x.Key.Value2,
Value3 = x.Key.Value3
}).ToList()
Is it possible to create the GroupBy and Select statements dynamically (the app already knows what columns it requires). I am looking for a code based approch, creating a select statement is not what i am looking for here.