ExecuteStoreQuery抛出System.Data.Entity.Core.EntityCommandExecutionException

时间:2016-04-28 05:42:08

标签: entity-framework stored-procedures

很抱歉,但是在阅读了很多接近问题的博客后,我无法解释错误。

我有以下存储过程

CREATE PROCEDURE dbo.AddUserToRole 
    @UserName nvarchar(256), @RoleId nvarchar(128),
    @UserId nvarchar(128) OUTPUT  
AS
BEGIN
  SET NOCOUNT ON;
  SELECT @UserId = Id FROM dbo.AspNetUsers WHERE dbo.AspNetUsers.UserName = @UserName
  INSERT INTO dbo.AspNetUserRoles (UserId,RoleId) VALUES(@UserId,@RoleId)
END
GO

我称之为:

var userNameParameter = new SqlParameter("UserName", userName);
var roleIdParameter = new SqlParameter("RoleId", roleId);
string userId = "";
var UserIdParameter = new SqlParameter("UserId", userId);
UserIdParameter.Direction = System.Data.ParameterDirection.Output;
((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<string>("AddUserToRole @UserName, @RoleId, @UserId", userNameParameter, roleIdParameter, UserIdParameter);

但我得到以下异常     数据阅读器有多个字段。多个字段对EDM原语或枚举类型无效。

再次抱歉,我将不胜感激任何帮助。我不想只是修复,但我想了解确切的问题是什么。

由于

1 个答案:

答案 0 :(得分:0)

尝试这样做

ExecuteStoreQuery<string>("Exec AddUserToRole  @UserName, @RoleId, @UserId", userNameParameter, roleIdParameter, UserIdParameter);