我在我的应用程序中使用 VS2010、Entity Framework 4.0 和 Advantage v. 10。我正在尝试使我在 Advantage DB 中定义的 UDF 可用于我的应用程序代码。设计师没有像我期望的那样在“从数据库更新模型”向导中的存储过程下显示 UDF。所以我手动将UDF添加到SSDL中,如下所示:
<Function Name="Test" ReturnType="numeric" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion">
<Parameter Name="PartID" Type="integer" Mode="In"/>
</Function>
我还添加了一个 CLR 方法存根:
[EdmFunction("namespace.Store", "Test")]
public static decimal Test(int partID)
{
throw new InvalidOperationException("Call from within an L2E query");
}
我可以在我的 Linq-to-Entities 语句中看到该函数;但是,生成的 SQL 无效。使用 ToTraceString,UDF 调用看起来像这样:
"namespace.Store"."Test"("Project3"."PartID") AS "C4"
这给了我以下错误:
System.Data.EntityCommandExecutionException:执行命令定义时出错。有关详细信息,请参阅内部异常。---> Advantage.Data.Provider.AdsException:错误 7200:AQE 错误:状态 = 42000;本机错误 = 2117; [iAnywhere 解决方案][Advantage SQL 引擎]意外标记:标量函数名称不应分隔。
如果我在 Advantage Data Architect 中运行生成的 SQL 并像这样更正函数名称,它工作正常:
Test("Project3"."PartID") AS "C4"
反正有没有告诉实体框架生成正确的 SQL?我在 SSDL 中的函数定义中做错了吗?
提前致谢。