Question

I am using VS2010, Entity Framework 4.0, and Advantage v. 10 in my application. I have written a Linq-to-Entities (L2E) statement that tries to convert a nullable numeric (decimal) type to a decimal. A simple statement might look like:

var x = (from test in entities.Tests
         select test.ValueA.HasValue ? test.ValueA.Value : 0);

However, I am receiving the following error:

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> Advantage.Data.Provider.AdsException: Error 7200: AQE Error: State = S0000; NativeError = 2159; [iAnywhere Solutions][Advantage SQL Engine]Invalid argument to scalar function: CAST - must specify both precision and scale. -- Location of error in the SQL statement is: xxx (line: x column: x) AdsCommand query execution failed.

Is there any way around this short of enumerating the results and doing the conversion on the client side? I am not sure how to tell Advantage the precision and scale of "0" through the L2E statement.

Thanks in advance.

Was it helpful?

Solution

As Craig mentioned this is a bug in the Advantage Entity Framework Provider. It will be fixed in the next service release of the Advantage Entity Framework Provider.

Another possible work around would be to expose the IsNULL function of the database. Add the following to the SSDL.

 <Function Name="IsNull" ReturnType="numeric" Aggregate="false" BuiltIn="true" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion">
    <Parameter Name="Value" Type="numeric" Mode="In"/>
    <Parameter Name="Default" Type="integer" Mode="In"/>
 </Function>

Then add the following CLR stub function.

  public static class MyFunctions
     {

     [EdmFunction( "Model.Store", "IsNull" )]
     public static decimal IsNull( decimal? Value, int? Default )
        {
        throw new InvalidOperationException( "Call from within an L2E query" );
        }
     }

OTHER TIPS

Your EF provider generated bad SQL, and that's a bug in the provider.

However, you can probably work around it:

var x = entities.Tests
                .Select(t => t.ValueA)
                .AsEnumerable()
                .Select(t => t.GetValueOrDefault());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top