实体框架 - 存储过程返回值 [英] Entity Framework - stored procedure return value

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

问题描述

我试图得到一个存储过程的返回值。下面是这样一个存储过程的例子:

I am trying to get the return value of a stored procedure. Here is an example of such a stored procedure:

select
    Name,
    IsEnabled
from
    dbo.something
where
    ID = @ID

if @@rowcount = 0
    return 1    

return

这是一个简单的选择。如果发现0行,我的结果集是空的,但我仍然有一个返回值。

This is a simple select. If 0 rows are found, my result set will be null, but I will still have a return value.

这是一个坏榜样,因为这是一个选择,所以相信我能找到,如果是返回0行。然而,在一个插入,删除或其他调用,我们需要这个返回值来知道是否有问题。我一直无法找到一种方式来获得这个返回值。我能得到的输出值,我可以得到结果集,但没有返回值。

This is a bad example, as this is a select, so sure I could find if 0 rows were returned. However, on an Insert, delete, or other calls, we need this return value to know if there was a problem. I have been unable to find a way to get this return value. I can get output values, I can get result sets, but no return value.

我能得到的返回值,如果我手动调用SQL,或者即使我跑的SqlCommand 使用实体框架,但是这不是我想做的事情。

I can get the return value if I call SQL manually, or even if I run a SqlCommand using the Entity Framework, but this is not what I want to do.

有没有人能使用实体框架的存储过程得到返回值?

Has anyone ever been able to get the return value from a stored procedure using Entity Framework?

感谢您的帮助!

推荐答案

没有。实体框架不具备丰富的存储过程的支持,因为它的ORM,而不是一个SQL替代品。

No. Entity Framework doesn't have rich stored procedure support because its an ORM, not a SQL replacement.

正如你已经发现,如果你需要使用不常见的(更存储过程高级?)功能,你将不得不使用良好的老式ADO.NET。

As you have already discovered, if you need to use less common (more advanced?) features of stored procedures, you'll have to use good old fashioned ADO.NET.

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

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