实体框架7 FromSql存储过程返回值 [英] Entity Framework 7 FromSql stored procedure return value
本文介绍了实体框架7 FromSql存储过程返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用Entity Framework 7中的新 FromSql
命令返回值。如果一切顺利,则存储过程返回值0,如果出错则返回1。发生。
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 occurs.
使用 FromSql
和 DbSet
可以例如
_dbContext.ExampleEntity.FromSql('someSproc', 'param')
如何从中得到标量返回值0或1?
How will you get the scalar return value of 0 or 1 from this?
推荐答案
类似于存储过程的支持仍然仍在积压中。
Looks like stored procedure support is still on the backlog.
这是一个示例扩展方法,您可以使用 _dbContext.ExecuteStoredProcedure( someSproc, param);
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();
}
}
这篇关于实体框架7 FromSql存储过程返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文