且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

执行非查询程序不起作用 asp.net 核心

更新时间:2023-02-16 21:54:04

从此链接获取帮助 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.