pdevito3 / QueryKit

🎛️ QueryKit is a .NET library that makes it easier to query your data by providing a fluent and intuitive syntax for filtering and sorting.
Apache License 2.0
147 stars 13 forks source link

Support Collection Properties #3

Closed pdevito3 closed 1 year ago

pdevito3 commented 1 year ago

Add support for something like Ingredients.Name == "salt" where Ingredients is a list. It should be equivalent to something like:

        var recipes = testingServiceScope.DbContext().Recipes
            .Include(x => x.Ingredients)
            .Where(x =>x.Ingredients.Any(y => y.Name == "salt"))
            .ToList();

Note Will handle primitive lists in another ticket

royston-c-oa commented 1 year ago

This would be a great addition and a significant improvement on Sieve. I'm happy to spend some time on it.

Personally, I'd love to see an API capable of:

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<Tag> Tags { get; set; }
}

public class Tag
{
    public int Id { get; set; }
    public string Name { get; set; }
}

var filterInput = """Tags.Id ^^ ["tag_id_1", "tag_id_2"]";
var config = new QueryKitConfiguration(config =>
{
    config.Property<Product>(x => x.Tags.Select(y => y.Id));
});

Extreme case:

public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<Address> Addresses { get; set; }
}

public class Address
{
    public int Id { get; set; }
    public string Street { get; set; }
    public List<Person> Residents { get; set; }
}

var filterInput = """Addresses.Residents.Id ^^ ["person_id_1", "person_id_2"]";
var config = new QueryKitConfiguration(config =>
{
    config.Property<Person>(x => x.Addresses.Select(y => y.Residents.Select(z => z.Id));
});

@pdevito3 Thoughts?

pdevito3 commented 1 year ago

👋 the short answer is that I completely agree -- this would be a huge value add to the library. I started with object lists because once this is done, primitive lists will be an easy tag on.

The problem is, it is really hard to get right with the current sprache implementation. I've been spinning my wheels with it for weeks now. I even started an AST implementation with Pidgin to see if that would lighten the load.

If you're willing to helping with this I'm more than open to it! 🍻

royston-c-oa commented 1 year ago

@pdevito3 I have added an example of what I was thinking for this to the draft PR: https://github.com/pdevito3/QueryKit/pull/7. It is pretty rough and would need rewriting but give a starting point for a discussion on the idea.

I couldn't find any other branches, but I'd be happy to review anything you have been experimenting with. I have a feeling I have missed something, as I didn't really need to adjust anything that uses the sprache lib.