Dapper örnek sorguları (.net core mvc projesinde, .net standart class library)


using Dapper;

  private readonly SqlConnection connection;

        private DynamicParameters parameter;

        private const string sqlAllUsers = "SELECT * FROM dbo.TbUsers ";

        private const string WHEREUserId = " WHERE UserId = @UserId ";

        private const string WHEREUserName = " WHERE UserName = @UserName ";


  public async Task<IEnumerable<TbUsers>> GetAllUsersAsync()

        {

             return await connection.QueryAsync<TbUsers>(sqlAllUsers);

        }



  public async Task<TbUsers> GetUserByUserIDAsync(int UserId)
        {
            parameter = new DynamicParameters();            
            parameter.Add("UserId", UserId);
            var res = await connection.QueryFirstOrDefaultAsync<TbUsers>(sqlAllUsers + WHEREUserId   , parameter);

            return  res; 
        }

Yorumlar