Entity Framework 7 FromSql stored procedure return value

前端 未结 1 423
梦谈多话
梦谈多话 2020-12-21 10:57

I am trying to return a value using the new FromSql command in Entity Framework 7. My stored procedure returns a value of 0 if all goes well and 1 if an error o

相关标签:
1条回答
  • 2020-12-21 11:41

    Looks like stored procedure support is still on the backlog.

    Here's an example extension method you can call using _dbContext.ExecuteStoredProcedure("someSproc", "param");.

    public static class DbContextExtension 
    {
        public static int ExecuteStoredProcedure(this DbContext context, string name, string parameter)
        {
            var command = context.Database.GetDbConnection().CreateCommand();
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = name;
            var param = command.CreateParameter();
            param.ParameterName = "@p0";
            param.Value = parameter;
            command.Parameters.Add(param);
            return (int)command.ExecuteScalar();
        }
    }
    
    0 讨论(0)
提交回复
热议问题