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

In NetCore 3.0 project, ToRanked not working #38

Open
irsali opened this issue Mar 5, 2020 · 2 comments
Open

In NetCore 3.0 project, ToRanked not working #38

irsali opened this issue Mar 5, 2020 · 2 comments

Comments

@irsali
Copy link

irsali commented Mar 5, 2020

Code looks like below:

return await _entities.Search(x => x.Propname).Containing(keywords.Split(' '))
                 .ToRanked().OrderByDescending(x => x.Hits)
                 .Select(x => x.Item)
                 .ToListAsync();

It seems to me the query created has some kind of issue:

System.InvalidOperationException: The LINQ expression 'DbSet
.Where(t => t.Propname.Contains("omni"))
.OrderByDescending(t => new Ranked{
Hits = (t.Propname ?? "").Length - (t.Propname ?? "").Replace(
oldValue: "omni",
newValue: "").Length / 4,
Item = t
}
.Hits)' 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 either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

Let me know if any other information could be useful to understand the problem.

@iemo2007
Copy link

iemo2007 commented Mar 16, 2021

I've the same problem

This code in the tutorial

var result = context.Users.Search(x => x.FirstName, x => x.LastName, x.MiddleName)
.Containing("John")
.ToRanked()
.OrderByDescending(r => r.Hits) // Order by Hits property of IRanked
.Take(10);

doesn't work and an exception raises with this message

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 either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

it works only when you convert the link query to Enumerable before calling OrderByDescending() but that doesn't make sense at all because by this way I get a lot of un needed rows from the database

@tommysor
Copy link

This issue should not occur when using Microsoft.EntityFrameworkCore.SqlServer Version >= 3.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants