I'm using entity framework 5, code first fluent API. I've built a simple query with a GroupBy for aggregation:
var query = context.Table1
.GroupBy(g => new
{
Prop1= g.Prop1,
Prop2 = g.Prop2
})
.Select(s => new
{
Prop1= s.Key.Prop1,
Prop2= s.Key.Prop2,
Avg = s.Average(m => m.Minutes),
Min = s.Min(m => m.Minutes),
Max = s.Max(m => m.Minutes),
StdDev = //How to get standard deviation of Minutes here?
})
.ToList();
Along with other aggregation (average, min, max), how can I get standard deviation of Minutes in my select? I've heard there is a canonical function for StdDev but have been unable to figure out how to apply it in this case. Any help or a nudge in the right direction would be greatly appreciated!
You should be able to use
EntityFunctions.StandardDeviation
inSystem.Data.Objects
like this:(If you were using EF 6, it would be
System.Data.Entity.DbFunctions.StandardDeviation()
)