本文介绍了从具有动态 sql 的存储过程创建实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储过程,它使用几个表并创建一个交叉表结果集.为了创建交叉表结果集,我使用了基于表中记录动态生成的 CASE 语句.

I have a stored procedure which uses a couple of tables and creates a cross-tab result set. For creating the cross-tab result set I am using CASE statements which are dynamically generated on basis of records in a table.

是否可以使用 ADO.NET 实体框架从此 SP 生成实体?因为每次我为特定的 SP 尝试 Get Column Information 时,它都会说 选定的存储过程不返回任何列.

Is it possible to generate an entity from this SP using ADO.NET Entity framework? Cuz each time I try Get Column Information for the particular SP, it says that The selected stored procedure returns no columns.

任何帮助将不胜感激.

推荐答案

我团队的一个成员最近遇到了这样的事情,其中​​一个存储过程正在生成各种动态 SQL 并返回计算列,因此数据上下文没有知道该怎么做.我自己还没有尝试过,但这是他声称有效的解决方案:

A member of my team recently encountered something like this, where a stored procedure was generating all kinds of dynamic SQL and returning calculated columns so the data context didn't know what to make of it. I haven't tried it myself yet, but this was the solution he claimed worked:

解决办法很简单,就是放行立即关闭;"进入过程.这允许数据上下文实际上生成返回类.这在这种情况下有效,只是因为proc除了查询什么都不做数据.

这里有完整的细节:http://tonesdotnetblog.wordpress.com/2010/06/02/solution-my-generated-linq-to-sql-stored-procedure-returns-an-int-何时应该返回表/

您只需要SET FMTONLY OFF"proc 足够长以生成班级.然后您可以将其注释掉.

You only need the "SET FMTONLY OFF" in the proc long enough to generate the class. You can then comment it out.

这篇关于从具有动态 sql 的存储过程创建实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:11