如何从存储过程中获取值?
ASP.NET MVC、VB.NET、SQL Server 2008 R2、Entity Framework v4
我创建了一个返回整数值的存储过程,
PROCEDURE [dbo].[spProfileCount]
@STARTLETTER char(1) = 'A'
AS
BEGIN
SET NOCOUNT ON
SELECT count(*)
FROM [Profils]
WHERE LEFT(lastname,1) = @STARTLETTER
END
我在 EF 中导入了存储过程并创建了一个函数。在该函数中,我将返回集合
定义为Int32
类型的标量(这与我按[获取列信息]
时看到的一致)代码> 按钮)。
那么这在控制器中是如何工作的呢?我尝试了很多事情但没有成功。
即
Dim n As Integer = 0
n = context.spProfileCount("Q")
错误:
System.data.Objects.ObjectResults(整数?)' 类型的值不能 转换为“整数”。
ASP.NET MVC, VB.NET, SQL Server 2008 R2, Entity Framework v4
I created a stored procedure that returns an integer value
PROCEDURE [dbo].[spProfileCount]
@STARTLETTER char(1) = 'A'
AS
BEGIN
SET NOCOUNT ON
SELECT count(*)
FROM [Profils]
WHERE LEFT(lastname,1) = @STARTLETTER
END
I imported the stored proc in EF and created a function. In that function I defined Returns a collection of
as scalar of type Int32
(which is consistent with what I see when I press the [get column information]
button).
So how does this work in the controller? I've tried many things without success.
I.e.
Dim n As Integer = 0
n = context.spProfileCount("Q")
Error:
Value of type System.data.Objects.ObjectResults(of integer?)' can not
be converted to 'integer'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过文档中显示的内容?
ObjectResult(Of T) 类。
如果您确定只有一行,那么它将只是
queryResult.Single()
Have you tried what is shown in the documentation?
ObjectResult(Of T) Class.
If you are sure you're going to have only one row, it's going to be just
queryResult.Single()