执行函数中的参数类型与函数返回的类型不兼容 [英] The type Parameter in Execute Function is incompatible with the type returned by the function

查看:189
本文介绍了执行函数中的参数类型与函数返回的类型不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm getting the following error when trying to import a stored proc as a function in Entity Framework 5. I have recently updated the data project to reference the new version of EF.


ExecuteFunction中的类型参数'SSDS.Data.testy_Result'是
与类型'SSDS.Data.testy_Result'不兼容由
函数返回。

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

我无法将其用于任何存储过程...这是我的简单测试一:

I can't get it to work for any stored proc...here is my simple test one:

CREATE PROCEDURE testy

AS
BEGIN
    select 'hello' as hello
END
GO

上面的异常会中断此处:

It breaks with the exception above here:

 public virtual ObjectResult<testy_Result> testy()
    {
        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<testy_Result>("testy");
    }

当我将结果设置为字符串标量时,没有错误模型设计器中的编辑功能导入窗口。

And there is no error when I set the result to a string scalar in the Edit Function Import window in the model designer.

我这样调用该函数:

private Entities db = new Entities();
var x = db.testy();

这里是否有明显的我想念的东西?我的项目中有几个edmx文件,其他文件是使用较旧版本的EF(并使用ObjectContext)创建的。

Is there something obvious that I'm missing here? There are a few edmx files in my project and the others were created with an older version of EF (and use ObjectContext).

功能映射:

更多功能映射详细信息:

More Function Mappings Detail:

testy_Result类:

testy_Result class:

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


推荐答案

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

I've been struggling with this same problem for the last few days. My project had also been upgraded from a previous version of Entity Framework to 5.0. I finally figured out it was due to having a mix of old and new edmxs. Removing the old edmx allowed the new one to work, but of course that's not a viable solution. I was also able to get it to work by changing the code generation strategy for the new (EF 5) edmx to "Legacy ObjectContext". If you're not familiar, this can be found by opening the edmx diagram, right-clicking, and going to Properties. I suspect all edmxs in the project just need to be on the same code generation strategy, so you could probably also change your old ones to T4 instead, although that would probably involve more work.

这篇关于执行函数中的参数类型与函数返回的类型不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆