英文:
Getting error 'ExecuteFunction only supports stored procedures that have a return type' when calling a stored procedure using EntityFramework
问题
在我的.NET应用程序中,使用Entity Framework,我已将一个存储过程(SP)添加到我的实体模式中。我像这样调用我的SP:
ObjectContext.ExecuteFunction<ReturnTypeObject>("StoredProcedure", param1, param2, ...);
当我运行这段代码时,我收到错误消息:
ExecuteFunction仅支持具有返回类型的存储过程。
我的SP包括多个表连接和插入到临时表中,最终以以下方式从最终表中选择:
SELECT
一些属性...
FROM #TempTable2
WHERE Rank1 = @ParameterRank
AND Rank2 = 1
DROP TABLE IF EXISTS #TempTable1
DROP TABLE IF EXISTS #TempTable2
END;
最终选择中的一些属性,如Rank1和Rank2,在ReturnTypeObject上不存在,我想知道这是否可能是问题的原因。
英文:
In my .Net application using Entity Framework I have added a SP to my entity schema. I call my SP like so
> ObjectContext.ExecuteFunction<ReturnTypeObject>("StoredProcedure",
> param1,param2,...);
When I run this code I get error
> ExecuteFunction only supports stored procedures that have a return
> type.
My SP includes multiple table joins and insertions into temp tables, ending in a select from a final table like so
SELECT
some properties...
FROM #TempTable2
WHERE Rank1 = @ParameterRank
AND Rank2 = 1
DROP TABLE IF EXISTS #TempTable1
DROP TABLE IF EXISTS #TempTable2
END;
Some of the properties in the final select like the Rank1 and Rank2 do not exist on the ReturnTypeObject , and I am wondering if that could be the problem.
答案1
得分: 1
我认为你想要使用 ExecuteStoreCommand
,它不会返回任何内容(除了“受影响的行数”,在这里不适用)。
英文:
I think you want ExecuteStoreCommand
, which does not expect any return (except "rows affected", which will not apply here)
答案2
得分: 0
我找到了我的解决方案。在注册了存储过程的 'Model.edmx' 中,在 '模型浏览器' 选项卡中,我必须找到该存储过程并将其返回类型设置为预期的对象,因为默认情况下它是 'none'。
英文:
I found out my solution. In the 'Model.edmx' in which the SP is registered, in the 'Model Browser' tab I had to find the SP and set it's return type to the expected object, since by default it is 'none'.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论