更新时间:2023-01-03 09:20:21
从此链接获得帮助 https://docs.microsoft.com/en-us/ef/core/querying/raw-sql
在 Core 2.0 或 EntityFramework 7 中不支持在 ef 6 的先前版本中可用的 SqlQuery 功能.
In Core 2.0 or EntityFramework 7 does not support SqlQuery feature which was available in previous version of ef 6.
以下是如何在 EntityFramework 7 中执行 sp 的示例.
Below is the example how you can execute sp in EntityFramework 7.
public List<UserDetails> GetUserDetailsUsingSP(int LoggedInID)
{
var loggedInUser = new SqlParameter("Id", LoggedInID);
return WidServices
.FromSql("EXECUTE WID_Services_GetAll @Id ", loggedInUser)
.FirstOrDefault();
}
注意:在您要在主数据库上下文类下添加 DbSet 的位置添加此方法,然后通过实例化 dbContext 调用此方法.
Note : Add this method where you are adding your DbSet under your main db context class and then call this method by instantiating your dbContext.