You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have not found anything in the docs that state my scenario isn't supported. I have also tested it with the latest version (6.0.1) because #26593 looks similar and is fixed. But my issue persists.
I have the following query in the old Entity Framework (.NET Framework):
So what happens is that you can pass a list of search string (the categorySearchStrings), e.g.:
"38.54.", "45."
This is basically an implementation of a search tree where each category in our database has a SearchTree property. So a category with search tree 38.54.99 would match, but 38. would not.
A product can have multiple categories and we can pass in multiple search tree strings to the query. So we're comparing two collections.
This gets translated to
SELECT
[GroupBy1].[A1] AS [C1]
FROM ( SELECTCOUNT(1) AS [A1]
FROM [dbo].[ProductVariation] AS [Extent1]
WHERE EXISTS (SELECT1AS [C1]
FROM ( SELECT
[Extent3].[SearchTree] AS [SearchTree]
FROM [dbo].[ProductCategory] AS [Extent2]
INNER JOIN [dbo].[Category] AS [Extent3] ON [Extent2].[CategoryId] = [Extent3].[Id]
WHERE [Extent1].[ProductId] = [Extent2].[ProductId]
) AS [Project1]
WHERE EXISTS (SELECT1AS [C1]
FROM ( SELECT1AS X ) AS [SingleRowTable1]
WHERE ( CAST(CHARINDEX(N'38.', [Project1].[SearchTree]) ASint)) =1
)
)
) AS [GroupBy1]
I'm trying to migrate to Entity Framework Core (6, running on .NET 6) but this now gives me the following error:
System.InvalidOperationException : The LINQ expression 'categorySearchString => categorySearchString == "" || EntityShaperExpression:
Company.Data.Models.Category
ValueBufferExpression:
ProjectionBindingExpression: Inner
IsNullable: False
.SearchTree != null && categorySearchString != null && EntityShaperExpression:
Company.Data.Models.Category
ValueBufferExpression:
ProjectionBindingExpression: Inner
IsNullable: False
.SearchTree.StartsWith(categorySearchString)' 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.
Switching to client evaluation isn't really an option I believe, because there's too many data that will be retrieved. Plus, there's more going on than just this Where clause. I simplified it.
With the help of StackOverflow I have a workaround, but it involves complicated code to build up an expression:
@roji This is a legacy app that we're migrating from .NET Framework 4.6 to .NET 6. I'm trying to keep the changes to a minimum because that's quite a lot of work in and of itself. HierarchyId is probably something that could be useful to replace the current system but as I've found a workaround with the expression, I'll leave it as is for the time being. Thanks for pointing me to that package though!
Thank you for pointing me to the duplicate. My apologies for not having found it.
The Issue
I have not found anything in the docs that state my scenario isn't supported. I have also tested it with the latest version (6.0.1) because #26593 looks similar and is fixed. But my issue persists.
I have the following query in the old Entity Framework (.NET Framework):
So what happens is that you can pass a list of search string (the categorySearchStrings), e.g.:
This is basically an implementation of a search tree where each category in our database has a
SearchTree
property. So a category with search tree38.54.99
would match, but38
. would not.A product can have multiple categories and we can pass in multiple search tree strings to the query. So we're comparing two collections.
This gets translated to
I'm trying to migrate to Entity Framework Core (6, running on .NET 6) but this now gives me the following error:
Switching to client evaluation isn't really an option I believe, because there's too many data that will be retrieved. Plus, there's more going on than just this Where clause. I simplified it.
With the help of StackOverflow I have a workaround, but it involves complicated code to build up an expression:
Version Info
EF Core version: 6.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.0.4
The text was updated successfully, but these errors were encountered: