entity framework7 FromSql存储过程返回值
我试图使用Entity Framework 7中的新FromSql
命令返回一个值。如果一切顺利,我的存储过程返回值0,如果发生错误,则返回1。
我们可以使用FromSql
和DbSet
来做
_dbContext.ExampleEntity.FromSql('someSproc', 'param')
你将如何得到标量返回值0或1?
看起来存储过程支持仍在积压中 。
这是一个可以使用_dbContext.ExecuteStoredProcedure("someSproc", "param");
调用的示例扩展方法_dbContext.ExecuteStoredProcedure("someSproc", "param");
。
上述就是C#学习教程:entity framework7 FromSql存储过程返回值分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
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(); } }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1033661.html