-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Contains on a tuple collection doesn't work #30320
Comments
Maybe it worked in 2.1 due to the query running client side? |
I suspect that was the case. I'm checking the tests in the PR. There are tests for the expression. As for tests for the generated SQL, it seems it is expected not to be translated, but evaluated client side? To be honest I don't get what we're asserting in these tests. public override void Contains_with_local_tuple_array_closure()
{
base.Contains_with_local_tuple_array_closure();
AssertSql(
@"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice]
FROM [Order Details] AS [o]",
//
@"SELECT [o].[OrderID], [o].[ProductID], [o].[Discount], [o].[Quantity], [o].[UnitPrice]
FROM [Order Details] AS [o]");
} |
Yeah, it's very likely this was simply client-evaluating in EF Core 2.1. var filter = new[]
{
Tuple.Create(1, 1),
Tuple.Create(2, 2)
};
var result2 = await dbContext.Customers
.Where(x => filter.Contains(new Tuple<int, int>(x.X1, x.X2)))
.ToListAsync(); Some relational databases (e.g. PG) support expressing this via Note that #26822 would allow expressing row values via C# value tuples - that issue is for comparison purposes but this could be made to work for the scenario above, on databases where that's supported. |
Thanks, @roji I assume the only way is to dynamically generate the expression and use OR (at least for a small list with few items). Does anyone have a better suggestion on how to accomplish it in EF? Btw, I have no further questions here, so the issue can be closed. Thanks. |
Yes, you'll need to manually create the expression tree for the Where operator via the factory APIs on the Expression class, and then pass that as the argument to Where. One good way to start is to inspect the expression tree on the IQueryable that's produced from your target query (look at it with a debugger without calling e.g. ToListAsync), and to reproduce the same thing. |
Hello,
This is not a new topic. I see there are closed issues back in 2017, version
2.1.0
. Issues: #9424, #10384. The PR is #9522.But, this doesn't seem to work anymore. Did we drop the support for it?
Sample App
Stack trace
The text was updated successfully, but these errors were encountered: