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] LINQ !Contains returns no result #1613

Closed
MuhKuh7 opened this issue Apr 5, 2020 · 3 comments
Closed

[BUG] LINQ !Contains returns no result #1613

MuhKuh7 opened this issue Apr 5, 2020 · 3 comments
Labels

Comments

@MuhKuh7
Copy link

MuhKuh7 commented Apr 5, 2020

Version
5.0.5

Describe the bug
The negated LINQ contains does not work

Code to Reproduce
This should get me all my objects where StringList does not contain myString
results = results.Where(x => !x.StringList.Contains(myString));
The resulting collection is empty however.

A workaround is:
results = results.Where(x => x.StringList.All(t => t != myString));

@MuhKuh7 MuhKuh7 added the bug label Apr 5, 2020
@ajmal-ahmed
Copy link

ajmal-ahmed commented Apr 12, 2020

this usually happens with LINQ query in LiteDB when you does not assign any value for a field it's considered as null (which in turn is a separate data type) and when you query that field you have to avoid those records.
As of now you might see your code first might work as
results = results.Where(x => (x.StringList!=null)&&(!x.StringList.Contains(myString)));

@lbnascimento
Copy link
Contributor

@MuhKuh7 This issue is fixed in master and its fix will be present in the next incremental release.

@MuhKuh7
Copy link
Author

MuhKuh7 commented Apr 14, 2020

Tested and works.
Thx for the fast fix!

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

3 participants