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’.
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()