实体框架4:所选存储过程不返回列 [英] Entity Framework 4: The selected stored procedure returns no columns

查看:194
本文介绍了实体框架4:所选存储过程不返回列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的SP中,我混合静态SQL和动态SQL:

  declare @result table 

RowNum bigint,
Id_and_Title varchar(max),
DaysLeft int,
cat_id int
);

然后,在动态SQL中,将结果插入到该表中:

  DECLARE @TSQL NVARCHAR(max); 
SET @TSQL = ......

(我使用 print @TSQL 所以我确定查询是可以的)

  insert into @结果
EXECUTE sp_executesql @TSQL

select * from @result

但是,当我尝试在VS 2010 Ultimate中导入taht SP时,我看到了我在标题中提到的消息。是什么原因?很多时候我发生了这个错误,但是我仍然不知道是什么原因导致的。

解决方案

尝试将此行添加到您的存储过程开始:

SET FMTONLY OFF

完成导入后,您可以将其删除。 p>

这篇文章(kind很长的路要走),它对我来说是有效的,虽然我已经回到ADO.NET,当时我非常依赖存储过程。请记住,如果您的列更改取决于实体模型将中断的动态SQL。


In my SP, I mix static SQL and dynamic SQL:

declare @result table
(
 RowNum bigint,
 Id_and_Title varchar(max),
 DaysLeft int,
 cat_id int
);

then, in the dynamic SQL I insert the result to that table:

DECLARE @TSQL NVARCHAR(max);
SET @TSQL = ......

(I use print @TSQL so I'm sure that the query is OK)

insert into @result
EXECUTE sp_executesql @TSQL

select * from @result

but, when I try to import taht SP in VS 2010 Ultimate I see the message as I mentioned in the title. What causes that ? For many times I've occured that error but I still don't know what causes that

解决方案

Try adding this line to the beginning of your stored procedure:
SET FMTONLY OFF
You can remove this after you have finished importing.

It's mentioned in this article (kind of a long way down) and it worked for me, although I have ended up going back to ADO.NET for the times when I am relying heavily on Stored Procedures. Bear in mind that if your columns change depending on the dynamic SQL your entity model will break.

这篇关于实体框架4:所选存储过程不返回列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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