Open enisn opened 3 years ago
Temporary solution is creating a nested query.
Create CountryFilterDto or use if it's already exist:
public class CountryFilterDto : FilterBase
{
[StringFilterOptions(StringFilterOption.Contains)]
public string Name { get; set; }
}
Place it into CityFilterDto
as same name with Navigation property of Entity
public class CityFilterDto : PaginationFilterBase
{
[CompareTo("Name")]
[StringFilterOptions(StringFilterOption.Contains)]
public string Filter { get; set; }
public CountryFilterDto Country { get; set; }
}
Write a setter method for Filter and set Country.Name parameter at t he same time with Filter:
public class CityFilterDto : PaginationFilterBase
{
private string filter;
[CompareTo("Name")]
[StringFilterOptions(StringFilterOption.Contains)]
public string Filter { get => filter; set => SetFilter(value); }
public CountryFilterDto Country { get; set; }
private void SetFilter(string value)
{
filter = value; // keep backing field.
if(Country == null)
Country = new CountryFilterDto();
Country.Name = value;
this.CombineWith = CombineType.Or; // Make sure combines with || instead of &&
}
}
That's it! Nested query will work properly. This solution is temporary until solution of this issue.
Following situation doesn't work for
Country.Name
:Expected Expression is:
.Where(x => x.Name.Contains("Turkey") || x.Country.Name.Contains("Turkey"))
Generated Expression is
.Where(x => x.Name.Contains("Turkey").Where(x.Name.Contains("Turkey")))