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

Chain filtering #17

Closed
cirrusone opened this issue Sep 16, 2021 · 2 comments
Closed

Chain filtering #17

cirrusone opened this issue Sep 16, 2021 · 2 comments
Assignees
Labels
bug Something isn't working close fixed enhancement New feature or request

Comments

@cirrusone
Copy link

cirrusone commented Sep 16, 2021

Is there a way to introduce chained logic so that there can be sub filters? For example based on the sample code below the filter Filter = "Level2List_Id=101, Level2List_Level3List_Property1>=3.0" might not do what is expected.

It currently finds Level2 items with Id=101 and Level3 items with Property1>=3.0 - but they do not have to be the same item.

Sometimes we need to chain filters so they apply to a single item, eg filter where Level2 item is BOTH Id=101 and also has Level3 items with Property1>=3.0.

For example, something like this

AND:
(Level2List_Id=101, Level2List_Level3List_Property1>=3.0) , Id < 10

OR:
(Level2List_Id=101| Level2List_Level3List_Property1>=3.0) , Id < 10

The example below returns 1 item as both conditions are met but with chained logic should return zero items as there is no data with Level2.Id == 101 and also Level3 Property1 >= 3.0.

        static void Main(string[] args)
        {
            Level1 level1 = new Level1()
            {
                Id = 1,
                Name = "Level1Name",
                Level2List = new List<Level2>()
                {
                    new Level2() { Id = 101, Name = "Level2_1", Level3List = new List<Level3>() { new Level3() { Property1 = 2.0, Property2 = 100.0, Level = 0 } } },
                    new Level2() { Id = 102, Name = "Level2_2", Level3List = new List<Level3>() { new Level3() { Property1 = 3.0, Property2 = 200.0, Level = 1 } } },
                    new Level2() { Id = 103, Name = "Level2_3", Level3List = new List<Level3>() { new Level3() { Property1 = 4.0, Property2 = 300.0, Level = 2 } } }
                }
            };

            Level1[] array = new Level1[1];
            array[0] = level1;
            var ds = array.AsQueryable();

            // Multi Nested Property
            var gq2 = new GridifyQuery { Filter = "Level2List_Id=101, Level2List_Level3List_Property1>=3.0" };
            var gm2 = new GridifyMapper<Level1>()
            .GenerateMappings()
            .AddMap("Level2List_Level3List_Property1", l1 => l1.Level2List.SelectMany(l2 => l2.Level3List).Select(l3 => l3.Property1))
            .AddMap("Level2List_Id", l1 => l1.Level2List.Select(l3 => l3.Id));

            var actual2 = ds.AsQueryable()
               .ApplyFiltering(gq2, gm2)
               .ToList();
        }

It may be required to actually specify what property (object or collection) is passed in the chain for sub-filtering.

@alirezanet alirezanet self-assigned this Sep 16, 2021
@alirezanet alirezanet added this to the Gridify Version 2 milestone Sep 16, 2021
@alirezanet alirezanet added the bug Something isn't working label Sep 16, 2021
alirezanet added a commit that referenced this issue Sep 16, 2021
@alirezanet alirezanet added the enhancement New feature or request label Sep 17, 2021
@alirezanet
Copy link
Owner

alirezanet commented Sep 17, 2021

Hi, this feature is available in version 2.0.0-beta.3.
If you use parenthesis around any nested collection that has the same type(like the above example), Gridify doesn't create separated queries.
I've tested many scenarios like this and it's working fine, but because of the massive complexity of this feature, you might find some use-cases that I did not cover yet.
I appreciate any feedback again.
thank you for your contribution.

@cirrusone
Copy link
Author

This is excellent! I've just tested briefly and it works really well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working close fixed enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants