-
Notifications
You must be signed in to change notification settings - Fork 227
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
The binary operator Equal is not defined for the types 'System.ValueTuple2[System.Net.IPAddress,System.Int32]' and 'System.ValueTuple
2[System.Net.IPAddress,System.Int32]'
#2458
Comments
Thanks, I can see the error happening. This is a tricky one. For the following LINQ query: _ = ctx.Entities
.Where(x => ctx.Entities.Select(e => e.Name).Contains(x.Name))
.ToList(); ... EF Core 3 translates to the following SQL: SELECT e."Id", e."IpAddress", e."Name"
FROM "Entities" AS e
WHERE e."Name" IN (
SELECT e0."Name"
FROM "Entities" AS e0
) ... while EF Core 6/7 translate to the following: SELECT e."Id", e."IpAddress", e."Name"
FROM "Entities" AS e
WHERE EXISTS (
SELECT 1
FROM "Entities" AS e0
WHERE e0."Name" = e."Name" OR ((e0."Name" IS NULL) AND (e."Name" IS NULL))) Now, this works well when the thing being compared is a simple string. When it's a value tuple, you get the exception since value tuples aren't really supported within expression trees yet (dotnet/roslyn#12897); concretely, trying to construct an Equal expression over two value tuples (as the above does) throws. I do have a possible hacky workaround though. If, instead of converting your var queryable = ctx.Entities
.Select(x => EF.Functions.Broadcast(EF.Functions.SetMaskLength(x.IpAddress, subnet)));
var count = await queryable
.Where(x => queryable.Contains(x))
.ToListAsync(); This should yield the same results as comparing cidrs. |
Thank, as a workaround, it's better used Will wait resolwe dotnet/roslyn#12897 |
Closing as there's nothing to be done on the EFCore.PG side. |
(If we care this is important), need to investigate more. The exception stack trace throws from The query posted by @roji if that is throwing then we may be able to be more resilient and generate object.Equals method which makes it work. |
@smitpatel, sorry, exception from another problem, with Join by ValueTuple as key. Correct full Exception
|
@roji, would you be able to add regression test for this in efcore.pg? Is there a way to write test in efcore repo? I have fix for this in efcore. |
…ng comparison in query Not all types implement equality operator, so it can throw exception. Reference types, Nullable<T> & known types are ok to be used with Expression.Equal Originally reported in npgsql/efcore.pg#2458
…ng comparison in query (#28608) Not all types implement equality operator, so it can throw exception. Reference types, Nullable<T> & known types are ok to be used with Expression.Equal Originally reported in npgsql/efcore.pg#2458
Sure, I can add a test here. To add a test in EF Core... Can we use InMemory to test for this (i.e. "persist" a value tuple and query it back)? |
But of course you want to test the relational code too... Can it be tested with a value converter maybe? |
When use
EF.Functions.Network
for work withcidr
, i get error when try contains operator in queryable:System.InvalidOperationException: The binary operator Equal is not defined for the types 'System.ValueTuple
2[System.Net.IPAddress,System.Int32]' and 'System.ValueTuple2[System.Net.IPAddress,System.Int32]'.
.This worked with EF Core 3.1. However after upgrading to EF Core 6, we get exception.
Test case
Full Example
Expected SQL
Exception
Full Exception
Include provider and version information
Runtime: 6.0.7
EF core: 6.0.5
Npgsql: 6.0.5
The text was updated successfully, but these errors were encountered: