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

Using Include, it's not possible to filter on the included document properties #3120

Closed
loraderon opened this issue Apr 9, 2024 · 1 comment
Labels

Comments

@loraderon
Copy link

[Fact]
public void include_to_dictionary_with_filter()
{
    var user1 = new User() { Age = 42 };
    var user2 = new User();

    var issue1 = new Issue { AssigneeId = user1.Id, Title = "Garage Door is busted" };
    var issue2 = new Issue { AssigneeId = user2.Id, Title = "Garage Door is busted" };

    using var session = theStore.IdentitySession();
    session.Store(user1, user2);
    session.Store(issue1, issue2);
    session.SaveChanges();

    using var query = theStore.QuerySession();
    var dict = new Dictionary<Guid, User>();

    var issues = query
        .Query<Issue>()
        .Include(x => x.AssigneeId, dict, u => u.Age == 42)
        .ToArray();

    issues.Length.ShouldBe(1);

    dict.Count.ShouldBe(1);
    dict.ContainsKey(user1.Id).ShouldBeTrue();
}
❌ Shouldly.ShouldAssertException : issues.Length
    should be
1
    but was
2

Originally posted by @loraderon in #3096 (comment)

@loraderon loraderon changed the title Using Include, it's not possible to filter on the included document properties Using Include, it's not possible to filter on the included document properties Apr 9, 2024
@jeremydmiller
Copy link
Member

@loraderon You don't have an filters on the main Issue document type. This test is invalid, and the existing behavior is correct. You're implying some behavior that is neither documented, not intended in any way. If you're wanting to do this with some kind of logical join, you might be better off using an ORM instead of a document database here.

If you really need to, you can use MatchesSql() and a sub query against the User document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants