开发者

How to use OutPut parameter in SP with EF 4.0

开发者 https://www.devze.com 2023-01-02 13:37 出处:网络
I updated my Model with my Stored procedure and in the model browser I can see it has a Function import as well.

I updated my Model with my Stored procedure and in the model browser I can see it has a Function import as well.

My SP inserts a record if none exists and returns a 1 else returns 0, pretty simple I think.

SP

CREATE PROCEDURE [dbo].[User_UpdateMessage]
(
@UserId int = 0, 
@UserId2 int = 0,
@Success bit = 0 OUTPUT
)
AS
BEGIN
SET NOCOUNT ON;

IF NOT EXISTS ( SELECT [UserIdFrom] FROM  [dbo].[MessageUpdate] WHERE [UserIdFrom] = @UserId AND [UserIdTo] = @UserId2 )
BEGIN
    INSERT INTO [dbo].[MessageUpdate] ([UserIdFrom], [UserIdTo])
    VALUES (@UserId, @UserId2)
    SELECT @Success = 1;
END
ELSE
    SELECT @Success = 0;
END

In my code I am calling the SP:

// Output Parameter
System.Data.Objects.ObjectParameter paramSucce开发者_高级运维ss1 = 
new System.Data.Objects.ObjectParameter("Success", typeof(byte));
_Entity.User_UpdateMessage(id, userId, paramSuccess1);

It is failing while executing the SP with the following error:

The data reader returned by the store data provider does not have enough columns for the query requested

[UPDATE]

As I was writing this I solved the problem. In the Model designer, the return type should be none, I had it to return Byte.

An answer to this question could be further enhancements or changes.


I too had the same problem, changed the return type to NONE instead of int32. Thanks saved me hours of debugging


you can use a 'select' statement in your stored procedure . it will solve the issue

Reference: http://codetunnel.com/blog/post/83/what-to-do-if-entity-framework-function-import-does-not-detect-any-columns-being-returned-by-your-stored-procedure


Try using this below..

// Output Parameter
System.Data.Objects.ObjectParameter paramSuccess1 = 
  new System.Data.Objects.ObjectParameter("Success", typeof(bool));
_Entity.User_UpdateMessage(id, userId, paramSuccess1);
0

精彩评论

暂无评论...
验证码 换一张
取 消