gpt4 book ai didi

entity-framework - Execute Function 中的类型参数与函数返回的类型不兼容

转载 作者:行者123 更新时间:2023-12-01 03:57:01 25 4
gpt4 key购买 nike

在 Entity Framework 5 中尝试将存储的 proc 作为函数导入时出现以下错误。我最近更新了数据项目以引用新版本的 EF。

The type parameter 'SSDS.Data.testy_Result' in ExecuteFunction is incompatible with the type 'SSDS.Data.testy_Result' returned by the function.



我无法让它适用于任何存储过程......这是我的简单测试:
CREATE PROCEDURE testy

AS
BEGIN
select 'hello' as hello
END
GO

它打破了上面的异常(exception):
 public virtual ObjectResult<testy_Result> testy()
{
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<testy_Result>("testy");
}

当我在模型设计器的 Edit Function Import 窗口中将结果设置为字符串标量时没有错误。

我这样调用函数:
private Entities db = new Entities();
var x = db.testy();

有什么明显的东西我在这里失踪了吗?我的项目中有一些 edmx 文件,其他文件是使用旧版本的 EF 创建的(并使用 ObjectContext)。

功能映射:

enter image description here

更多功能映射详情:

enter image description here

testy_Result 类:
  public partial class testy_Result
{
public string hello { get; set; }
}

最佳答案

在过去的几天里,我一直在努力解决同样的问题。我的项目也从以前版本的 Entity Framework 升级到 5.0。我终于发现这是由于新旧 edmxs 的混合。删除旧的 edmx 允许新的 edmx 工作,但这当然不是一个可行的解决方案。我还能够通过将新的 (EF 5) edmx 的代码生成策略更改为“Legacy ObjectContext”来使其工作。如果您不熟悉,可以通过打开 edmx 图表、右键单击并转到“属性”来找到它。我怀疑项目中的所有 edmx 只需要采用相同的代码生成策略,因此您可能也可以将旧的改为 T4,尽管这可能会涉及更多的工作。

关于entity-framework - Execute Function 中的类型参数与函数返回的类型不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16443092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com