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

[BUG] Any/All requires simple parameter on left side #2475

Open
ssteiner opened this issue Apr 18, 2024 · 0 comments
Open

[BUG] Any/All requires simple parameter on left side #2475

ssteiner opened this issue Apr 18, 2024 · 0 comments
Labels

Comments

@ssteiner
Copy link

ssteiner commented Apr 18, 2024

Version 5.0.17

I know, it's a known issue, but there's something fishy:

Here's my models

    class PhoneBookCategory
    {
        public Guid Id { get; set; }
       [BsonRef("PhoneBook")]
        public List<PhoneBook> PhoneBooks { get; set; }
    }

    class PhoneBook
    {
        public Guid Id { get; set; }
    }

And here's how I'm trying to query:

    List<Guid> ids = [Guid.NewGuid()];
    var set = GetCollection<PhoneBookCategory>().Query().Where(x => x.PhoneBooks.Select(x => x.Id).Any(x => ids.Contains(x)))

And it throws. But... I have a simple condition, no? x.PhoneBooks.Select(x => x.Id).Any(x => ids.Contains(x)), that's not performing an any over a full collection, only a list of Ids.

The exception message being x.Customers.Select(c => c.Name).Any(n => n.StartsWith('J')) to me it seems this is the same thing, no?
Could it be an issue of subdocuments versus DbRefs? and if so, isn't the exception misleading in this case?

Also.. I know how to rewrite the above query - but what if I were to query a more complex variety:

    var set = GetCollection<PhoneBookCategory>().Query().Where(x => x.PhoneBooks == null || x.PhoneBooks.Count == 0 || x.PhoneBooks.Select(x => x.Id).Any(x => ids.Contains(x)))

Is there a way to get the BsonExpression out of my two conditions so I can use the Query class to combine them together?

@ssteiner ssteiner added the bug label Apr 18, 2024
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

1 participant