Sushant Torankar

Sushant Torankar

  • 1.1k
  • 255
  • 28.2k

About FromSqlRaw function in web api

May 24 2022 12:54 PM

Hello,

I am using asp.net core web api ani sql server in my project

Following is my code to get all users :

 public async Task<List<UserMaster>> GetAllUsers()
        {
            var users = await _usersContext
             .UserMasters
             .FromSqlRaw("exec uspGetAllUsers")
             .ToListAsync();

            return users;
        }

 

it works fine,but I have to mention all columns of UsrMaster table in uspGetAllUsers procedure

I don't want to mention unnecessary columns in sql stored procedure

For ex, If Usermaster table has 10 columns , I have to mention all 10 columns in stored procedure, wheere as I just want to bind 4 columns in procedure

how to achieve this ?

 

Thank you


Answers (3)