更新时间:2023-02-16 22:07:07
从此链接获取帮助在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();
}
注意:在要在主db上下文类下添加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.