Closed AlexMKotcz closed 4 months ago
You can use it to filter on the count of a collection, you can prefix some of the operators with a #. For example, if i wanted to get all recipes that have more than 0 ingredients:
var input = """"Ingredients #>= 0"""";
full test example:
[Fact]
public async Task can_filter_by_string_for_collection_with_count()
{
// Arrange
var testingServiceScope = new TestingServiceScope();
var faker = new Faker();
var fakeIngredientOne = new FakeIngredientBuilder()
.WithName(faker.Lorem.Sentence())
.Build();
var fakeRecipeOne = new FakeRecipeBuilder().Build();
fakeRecipeOne.AddIngredient(fakeIngredientOne);
var fakeIngredientTwo = new FakeIngredientBuilder()
.WithName(faker.Lorem.Sentence())
.Build();
var fakeRecipeTwo = new FakeRecipeBuilder().Build();
fakeRecipeTwo.AddIngredient(fakeIngredientTwo);
await testingServiceScope.InsertAsync(fakeRecipeOne, fakeRecipeTwo);
var input = $"""Title == "{fakeRecipeOne.Title}" && Ingredients #>= 1""";
// Act
var queryableRecipes = testingServiceScope.DbContext().Recipes;
var appliedQueryable = queryableRecipes.ApplyQueryKitFilter(input);
var recipes = await appliedQueryable.ToListAsync();
// Assert
recipes.Count.Should().Be(1);
recipes[0].Id.Should().Be(fakeRecipeOne.Id);
}
I understand, but my question is specifically about the operators #==
and #!=
, I couldn't find a use case.
You mean general use cases? In the example above you could filter for recipes that only have 3 ingredients
Or are you saying the above doesn't actually work and it should?
Hmm I mean, I'm asking about the #==
and #!=
operators but your answer only mentions the #>=
, I want to know about the Equals
and Not Equals
Count Operator
.
Is that not what I just called out? The actual usage would look like var input = """"Ingredients #== 3"""";
same as the others just with the given operator
Oops! Now I get it. Thanks a lot.
Hello, I'm sorry, but can you please explain how to use the
#==
and#!=
operators? Just one example is enough. Thanks in advance.