如何使用 EF 在 asp.net 核心中使用存储过程
how to use stored procedure in asp.net core using EF
我正在开发一个 asp.net 核心应用程序,我在其中使用 EF 进行数据库操作。在某些情况下,我需要使用存储过程。所以当我尝试这样做时,我得到了错误。以下是我使用的代码,
var result = await _context.Query<EmployeeResult>().FromSqlRaw("[usp_getEmployeedetails] @employeeID,@purpose", new SqlParameter("@employeeID", employeeID), new SqlParameter("@purpose", purpose)).ToListAsync();
这里的“EmployeeResult”是一个 ViewModel。在 Sp 内部,我使用多个表来创建结果 select 查询。
报错信息如下"Cannot create a DbSet for 'EmployeeResult' because this type is not included in the model for the context."
谁能帮我解决这个问题?
给你添加这个代码dbcontext
public DbSet<EmployeeResult> EmployeeResults { get; set; }
我正在开发一个 asp.net 核心应用程序,我在其中使用 EF 进行数据库操作。在某些情况下,我需要使用存储过程。所以当我尝试这样做时,我得到了错误。以下是我使用的代码,
var result = await _context.Query<EmployeeResult>().FromSqlRaw("[usp_getEmployeedetails] @employeeID,@purpose", new SqlParameter("@employeeID", employeeID), new SqlParameter("@purpose", purpose)).ToListAsync();
这里的“EmployeeResult”是一个 ViewModel。在 Sp 内部,我使用多个表来创建结果 select 查询。
报错信息如下"Cannot create a DbSet for 'EmployeeResult' because this type is not included in the model for the context."
谁能帮我解决这个问题?
给你添加这个代码dbcontext
public DbSet<EmployeeResult> EmployeeResults { get; set; }