Я хочу загрузить отфильтрованные данные из базы данных.
Здесь он фильтрует данные
return predicate
.And(true, () => company => !String.IsNullOrEmpty(searchCriteria.Keyword) ? searchCriteria.Keyword.Contains(company.Name) : true)
.Or(true, () => company => !String.IsNullOrEmpty(searchCriteria.Keyword) ? company.Employees.Any(x => x.FirstName == searchCriteria.Keyword) : true)
.Or(true, () => company => !String.IsNullOrEmpty(searchCriteria.Keyword) ? company.Employees.Any(x => x.LastName == searchCriteria.Keyword) : true)
.And(true, () => company => searchCriteria.EmployeeDateOfBirthFrom != null ? company.Employees.Any(x => x.DateOfBirth >= searchCriteria.EmployeeDateOfBirthFrom) : true)
.And(true, () => company => searchCriteria.EmployeeDateOfBirthTo != null ? company.Employees.Any(x => x.DateOfBirth <= searchCriteria.EmployeeDateOfBirthTo) : true)
.And(true, () => company => searchCriteria.EmployeeJobTitles != null ? company.Employees.Any(x=> searchCriteria.EmployeeJobTitles.Any(s=> s == x.JobTitle.ToString())) : true);
, а здесь я загружаю данные из базы данных:
return await dbContext.Companies.Include(x => x.Employees).Where(predicate).ToListAsync();
Почему у меня возникла эта проблема и можно ли ее исправить?
System.InvalidOperationException: The LINQ expression 'DbSet<Employee>
.Where(e => EF.Property<Nullable<long>>((EntityShaperExpression:
EntityType: Company
ValueBufferExpression:
(ProjectionBindingExpression: EmptyProjectionMember)
IsNullable: False
), "Id") != null && EF.Property<Nullable<long>>((EntityShaperExpression:
EntityType: Company
ValueBufferExpression:
(ProjectionBindingExpression: EmptyProjectionMember)
IsNullable: False
), "Id") == EF.Property<Nullable<long>>(e, "CompanyId"))
.Any(e => __searchCriteria_EmployeeJobTitles_0
.Contains(e.ToString()))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.<VisitMethodCall>g__CheckTranslated|8_0(ShapedQueryExpression translated, <>c__DisplayClass8_0& )