Dixin / EntityFramework.Functions

EntityFramework.Functions library implements Entity Framework code first support for stored procedures (with single result type, multiple result types, output parameter), table-valued functions (returning entity type, complex type), scalar-valued functions (composable, non-composable), aggregate functions, built-in functions, niladic functions, and model defined functions.
https://weblogs.asp.net/Dixin/EntityFramework.Functions
MIT License
79 stars 27 forks source link

SqlSyntaxError for MariaDB Database with non composable scalar valued function #36

Open Streissi opened 5 years ago

Streissi commented 5 years ago

Hi i am using EntityFramework.Functions to call my stored functions on a MariaDb database server. Where i get the following error when i am calling my function:

System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[next_pdomatid](1)' at line 1
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.EntityFramework.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   --- End of inner exception stack trace ---
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Entity.Core.Objects.ObjectContext.CreateFunctionObjectResult[TElement](EntityCommand entityCommand, ReadOnlyCollection`1 entitySets, EdmType[] edmTypes, ExecutionOptions executionOptions)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass47`1.<ExecuteFunction>b__46()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass47`1.<ExecuteFunction>b__45()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, ExecutionOptions executionOptions, ObjectParameter[] parameters)
   at Pai.CCL.EF.DAL.CCLDbContext.NextPdoMatId(Int32 count) in D:\Tatmetal\CCL\Source\Pai.CCL\Pai.CCL.EF\DAL\CCLDbContext.cs:line 64
   at Pai.CCL.Services.CCLService.GetNewMaterialId() in D:\Tatmetal\CCL\Source\Pai.CCL\Pai.CCL\Services\CCLService.cs:line 129

The definition looks like following;

        [Function(FunctionType.NonComposableScalarValuedFunction, "next_pdomatid", Schema = "")]
        [return: Parameter(DbType = "int")]
        public int NextPdoMatId([Parameter(DbType = "int")]int count)
        {
            var countParameter = new ObjectParameter("count", count);

            return this.ObjectContext()
                .ExecuteFunction<int>("next_pdomatid",
                    countParameter).SingleOrDefault();
        }

When i run the function with HeidiSQL the query looks like this:

SELECT next_pdomatid('1')

and a query with the [], there i get the same error.

Is there any chance to set it up to not to use the []?

Streissi commented 5 years ago

i think the problem is on https://github.com/Dixin/EntityFramework.Functions/blob/2d557a1853368655eb7a4a5c46e98c6418dee1c6/EntityFramework.Functions/Function.MethodInfo.cs#L44