Stored procedure with EF core 1

Stored procedure with EF core

var emailAddressParam = new SqlParameter("@emailAddress", id.EmailAddress);
var passwordParam = new SqlParameter("@passwordHash", id.PasswordHash);

var users = context
            .UserProfiles
            .FromSqlRaw("exec sp_GetUsers @emailAddress, @passwordHash", emailAddressParam, passwordParam)
            .ToList();

Here is what the above code is Doing:
1. Create a new instance of the SqlParameter class for each parameter in the stored procedure.
2. Use the FromSqlRaw method to execute the stored procedure.
3. Pass the SqlParameter instances to the stored procedure.
4. Use the ToList method to return the results as a list of UserProfile objects.

Similar Posts