[英]how to use stored procedure in asp.net core using EF
I am working on an asp.net core application where I am using EF for database operations.我正在开发一个 asp.net 核心应用程序,我在其中使用 EF 进行数据库操作。 In some cases, I need to use Stored procedures.
在某些情况下,我需要使用存储过程。 So when I tried to do so, I get errors.
因此,当我尝试这样做时,出现错误。 The following is the code I used,
以下是我使用的代码,
var result = await _context.Query<EmployeeResult>().FromSqlRaw("[usp_getEmployeedetails] @employeeID,@purpose", new SqlParameter("@employeeID", employeeID), new SqlParameter("@purpose", purpose)).ToListAsync();
Here the "EmployeeResult" is a ViewModel.这里的“EmployeeResult”是一个 ViewModel。 Inside the Sp, I am using multiple tables to create the result select query.
在 Sp 内部,我使用多个表来创建结果选择查询。
The error message as follows "Cannot create a DbSet for 'EmployeeResult' because this type is not included in the model for the context."
错误消息如下
"Cannot create a DbSet for 'EmployeeResult' because this type is not included in the model for the context."
Can anyone help me to resolve the issue?谁能帮我解决这个问题?
将此代码添加到您dbcontext
public DbSet<EmployeeResult> EmployeeResults { get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.