Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Queries don't work with CompareToAttribute #17

Open
enisn opened this issue Nov 20, 2020 · 1 comment
Open

Nested Queries don't work with CompareToAttribute #17

enisn opened this issue Nov 20, 2020 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@enisn
Copy link
Owner

enisn commented Nov 20, 2020

Following situation doesn't work for Country.Name:

 public class CityFilterDto : BaseFilterDto
 {
     [CompareTo("Name", "Country.Name")]
    [StringFilterOptions(StringFilterOption.Contains)]
    public string Filter { get; set; }
}
  • 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")))

@enisn enisn added the bug Something isn't working label Nov 20, 2020
@enisn enisn self-assigned this Nov 20, 2020
@enisn
Copy link
Owner Author

enisn commented Nov 20, 2020

Temporary Solution

Temporary solution is creating a nested query.

  1. Create CountryFilterDto or use if it's already exist:
public class CountryFilterDto : FilterBase
{
    [StringFilterOptions(StringFilterOption.Contains)]
    public string Name { get; set; }
}
  1. 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; }
}
  1. 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.

@enisn enisn changed the title Nested Queries doesn't work with CompareToAttribute Nested Queries don't work with CompareToAttribute Jan 6, 2022
@enisn enisn added this to the V3.0 - Much more Dynamics milestone Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant