繁体   English   中英

Microsoft.EntityFrameworkCore 中 ExecuteScalar 的对应项

[英]Counterpart of ExecuteScalar in Microsoft.EntityFrameworkCore

插入完成后,我的存储过程有 SELECT SCOPE_IDENTITY() 。 使用 ADO.net 提供 ExecuteScalar 以在调用存储过程时检索相同的内容。

Microsoft.EntityFrameworkCore(Version=3.1.5.0) 中是否有类似的功能,它可以在执行 sp 后返回 SCOPE_IDENTITY。 我看到它有 ExecuteSqlRaw 但它只返回受影响的行。

你可以这样做:

using (var db = new NorthwindContext())
{
    var result = db.Set<IntReturn>()
    .FromSqlRaw("exec dbo.Scalar")
    .AsEnumerable()
    .First().Value;
    
    Console.WriteLine(result);
}

有关更多详细信息,请参阅我的博客文章: https://erikej.github.io/efcore/2020/05/26/ef-core-fromsql-scalar.ZFC35FDC70D5FC69D269883A8

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM