1

我在我的应用程序中使用 VS2010、Entity Framework 4.0 和 Advantage v. 10。我编写了一个 Linq-to-Entities (L2E) 语句,该语句尝试将可为空的数字(十进制)类型转换为十进制。一个简单的语句可能如下所示:

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

但是,我收到以下错误:

System.Data.EntityCommandExecutionException:执行命令定义时出错。有关详细信息,请参阅内部异常。---> Advantage.Data.Provider.AdsException:错误 7200:AQE 错误:状态 = S0000;本机错误 = 2159; [iAnywhere 解决方案][Adv​​antage SQL 引擎]标量函数的参数无效:CAST - 必须同时指定精度和小数位数。-- SQL 语句中的错误位置是:xxx (line: x column: x) AdsCommand 查询执行失败。

除了枚举结果并在客户端进行转换之外,有什么方法可以解决吗?我不确定如何通过 L2E 语句告诉 Advantage “0”的精度和比例。

提前致谢。

4

2 回答 2

1

正如 Craig 所说,这是 Advantage Entity Framework Provider 中的一个错误。它将在 Advantage Entity Framework Provider 的下一个服务版本中修复。

另一种可能的解决方法是公开数据库的 IsNULL 函数。将以下内容添加到 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>

然后添加以下 CLR 存根函数。

  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" );
        }
     }
于 2010-08-25T22:54:34.677 回答
0

您的 EF 提供程序生成了错误的 SQL,这是提供程序中的一个错误。

但是,您可能可以解决它:

var x = entities.Tests
                .Select(t => t.ValueA)
                .AsEnumerable()
                .Select(t => t.GetValueOrDefault());
于 2010-08-24T21:01:01.797 回答