ef-core-2.1 - ExecuteSqlCommand 返回 -1?
问题描述
我试图从代码中调用存储过程,在 ef core 2 中我发现我可以使用context.database.ExecuteSqlCommand()函数来执行我的数据库中的任何存储过程。
虽然存储过程在我的 sql server 实例中运行良好:
using (var context = new AZPDBDEMOGZContext(optionsBuilder.Options))
{
var existUser = context.Database.ExecuteSqlCommand("GetIdUsager_ByNomPrenomEmail @p0,@p1,@p2", parameters:new[] { "rouarouarouarouaroua", "wiem", "test@gmail.com" });
}
什么mi兴奋剂错了?
解决方案
ExecuteSqlCommand 只会为 DML 查询(即插入/更新/删除)返回“受影响的行”整数。您的存储过程看起来像是在返回一个结果集,因此它返回 -1,因为您没有提供更改数据源的语句。您需要创建一个 POCO 并使用 FromSql 来填充它。
推荐阅读
- git - git错误:找不到与指定用户ID匹配的身份
- reactjs - 如何键入 React ref 访问数组中的 DOM 元素
- html - CSS 过渡:不透明度和可见性过渡不适用于 Firefox(适用于 Chrome / Safari)
- javascript - 将字符串转换为 Javascript
- dynamics-crm - 数据工厂链接服务通用数据服务
- php - 如何使用 PHPUnit 测试构造函数的正确调用
- macos - 如何在macos上查找dmg文件的版本
- flutter - Flutter:Cloud Firestore serverTimestamp() 使文档读取加倍
- php - WooCommerce 结帐 - 更新运费
- ios - 扩展如何与 Swift 中的类一起工作?