I've built a custom aggregate
CREATE AGGREGATE Helpers.Median(@input REAL)
RETURNS REAL EXTERNAL NAME Aggregates.Median
Written this in edmx:
<Function Name="Median" Aggregate="true" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="Helpers" ReturnType="float">
<Parameter Name="input" Type="Collection(float)" Mode="In" />
</Function>
Created this class:
public class MySqlFunctions
{
[DbFunction("Entities.Store", "Median")]
public static float Median(IEnumerable<float> arg)
{
throw new NotSupportedException("Direct calls are not supported.");
}
}
Executed
using (Entities context = new Entities ())
{
var q = context.DataTable
.GroupBy(x => x.ID
, y => y.Value
, (k, g) => new { k,
c=MySqlFunctions.Median(g) }
).ToList();
}
And got this error:
System.NotSupportedException: 'The specified method 'Single Median(System.Collections.Generic.IEnumerable`1[System.Single])' on the type 'em_PriceTrackerModel.Store.MySqlFunctions' cannot be translated into a LINQ to Entities store expression because its return type does not match the return type of the function specified by its DbFunction attribute.'
What did I do wrong?