![](/img/trans.png)
[英]'Migrations' does not exist in the namespace 'Microsoft.EntityFrameworkCore'
[英]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.