1

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?

1 Answer 1

1

Add this code to you dbcontext

public DbSet<EmployeeResult> EmployeeResults { get; set; }
Sign up to request clarification or add additional context in comments.

6 Comments

Does this EmployeeResult need to be present in the DB?
No. Just class or viewmodel you are using like this should be added into your context.
Does the scaffolding the DB context again will remove these changes? Because in some cases the tables may alter or new tables may come. Since we are on the initial stage of the development.
No need to scaffolding after adding this Dbset. Just build again your project. New scaffolding does not remove this.
Thanks, Afshin. Also if the stored procedure returns multiple select queries then how to handle that situation?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.