Eldho George
Eldho George

Reputation: 55

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. 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. Inside the Sp, I am using multiple tables to create the result select query.

The error message as follows "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?

Upvotes: 1

Views: 422

Answers (1)

Afshin
Afshin

Reputation: 1509

Add this code to you dbcontext

public DbSet<EmployeeResult> EmployeeResults { get; set; }

Upvotes: 1

Related Questions