实体框架 +优势数据库:转换可为空的数字类型
我在我的应用程序中使用 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 Solutions][Advantage SQL Engine]标量函数的参数无效:CAST - 必须同时指定精度和小数位数。 -- SQL 语句中的错误位置为:xxx(行:x 列:x) AdsCommand 查询执行失败。
有没有办法解决这个枚举结果并在客户端进行转换的问题?我不知道如何通过L2E语句告诉Advantage“0”的精度和小数位数。
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Craig 提到的,这是 Advantage Entity Framework Provider 中的一个错误。它将在 Advantage Entity Framework Provider 的下一个服务版本中修复。
另一种可能的解决方法是公开数据库的 IsNULL 函数。将以下内容添加到 SSDL。
然后添加以下 CLR 存根函数。
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.
Then add the following CLR stub function.
您的 EF 提供程序生成了错误的 SQL,这是提供程序中的错误。
但是,您也许可以解决它:
Your EF provider generated bad SQL, and that's a bug in the provider.
However, you can probably work around it: