Home:ALL Converter>EntityCommandCompilationException specified method not supported Entity Framework

EntityCommandCompilationException specified method not supported Entity Framework

Ask Time:2016-08-24T21:29:57         Author:Alfred Waligo

Json Formatter

I am new to Entity Framework and I keep getting the EntityCommandCompilationException specified method not supported in Entity Framework. I can't figure out why this exception is being raised.

I have created a custom UDF aggregate function my_Func() for my installation of MySQL server 5.7 using the guidelines posted here. It works just like any ordinary aggregate function e.g. Sum() would work. i.e. I can execute the statement select my_Func(Column4) from db.table and it returns the desired result as a double. I have tested it and it works in MySQL server. I want to be able to use this method in a linq to entities query and in order to do this I have done the following.

using (var context = new dbEntities())
        {
            var results = from items in context.table
                          group items by new
                          { items.Column1, items.Column2 } into groupingItem
                          select new OutputType()
                          {
                              GroupedResult = groupingItem.OrderBy(x => x.Column3).Select(x => x.Column4).my_Func()
                          };
        }

I created a static class which contains the method.

public static class ModelDefinedFunctions
    {
        [DbFunction("dbModel.Store", "my_Func")]
        public static double my_Func(this IEnumerable<double> items)
        {
            throw new NotSupportedException("Direct calls are not supported.");
        }

    }

in the .edmx file I have added the following tag manually

<Function Name="my_Func" ReturnType="double" Aggregate="true" 
            BuiltIn="false" NiladicFunction="false" 
            IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="db">
            <Parameter Name="value" Type="Collection(double)" Mode="In" />
        </Function> 

Author:Alfred Waligo,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39124733/entitycommandcompilationexception-specified-method-not-supported-entity-framewor
yy