I have merged 3 tables together , now I would like to filter that new table using lazy loading
so i can filter the data with search inputs
C# code:
[HttpGet("AllWorkers")]
public async Task<IEnumerable<AllWorkersDto>> AllWorkers([FromQuery]AllWorkersFilterDto dto)
{
var DbData = _dbContext.UserRoles.Join(
_dbContext.Roles,
userRoles => userRoles.RoleId,
Role => Role.Id,
(userRoles, Role) => new
{
userId = userRoles.UserId,
rolename = Role.Name,
roledescription = Role.Description,
}).Join(_dbContext.Users,
Roles => Roles.userId,
Users => Users.Id,
(Roles, Users) => new AllWorkersDto
{
id = Users.Id.ToString(),
Name = Users.FirstName,
LastName = Users.LastName,
Email = Users.Email,
Role = Roles.rolename,
}).ToListAsync().Result;
IQueryable<AllWorkersDto> data = DbData.AsQueryable();
if (!string.IsNullOrWhiteSpace(dto.Name))
data = data.Where(x => x.Name.ToLower().Contains(dto.Name.ToLower()));
if (!string.IsNullOrWhiteSpace(dto.LastName))
data = data.Where(x => x.LastName.ToLower().Contains(dto.LastName.ToLower()));
if (!string.IsNullOrWhiteSpace(dto.Email))
data = data.Where(x => x.Email.ToLower().Contains(dto.Email.ToLower()));
if (!string.IsNullOrWhiteSpace(dto.Role))
data = data.Where(x => x.Role.ToLower().Contains(dto.Role.ToLower()));
return await data.ToListAsync();
}
it is returning a 500 error, can someone help me with this

