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

Add support for logical XOR #34736

Closed
OronDF343 opened this issue Sep 23, 2024 · 2 comments
Closed

Add support for logical XOR #34736

OronDF343 opened this issue Sep 23, 2024 · 2 comments

Comments

@OronDF343
Copy link

Currently, EF Core does not support logical XOR.

For example, let's say I want to find all order items not deleted that are missing SerialNumber or Barcode, but not both. This query fails to compile:

db.OrderItems.Where(i => !i.IsDeleted && (i.SerialNumber != null ^ !string.IsNullOrEmpty(i.Barcode)))
System.InvalidOperationException: The LINQ expression 'DbSet<OrderItem>()
    .Where(d => !(d.IsDeleted) && d.SerialNumber != null ^ !(string.IsNullOrEmpty(d.Barcode)))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

Instead I have to write it out like this:

db.OrderItems.Where(i => !i.IsDeleted && (i.SerialNumber != null && string.IsNullOrEmpty(i.Barcode) || i.SerialNumber == null && !string.IsNullOrEmpty(i.Barcode)))

It would be nice if EF Core did this translation automatically.

@roji
Copy link
Member

roji commented Sep 23, 2024

Duplicate of #16645

@roji roji marked this as a duplicate of #16645 Sep 23, 2024
@roji
Copy link
Member

roji commented Sep 23, 2024

This was done for 9.0 - give the rc.1 version a try!

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants