Hi @Tam Luong
System.InvalidOperationException: 'The LINQ expression 's => EntityShaperExpression: Website.Models.Product ValueBufferExpression: ProjectionBindingExpression: EmptyProjectionMember IsNullable: False .Content.Contains(s)' 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.'
As the error message said, you need to rewrite the query statement. Try to add AsEnumerable()
or ToList()
before the where
clause.
After modifying the code as below:
var searchs = new List<string> { "a1", "a2", "a3" };
var result = db.Products.AsEnumerable().Where(p => searchs.Any(s => p.Content.Contains(s))).ToList();
Or
var searchs = new List<string> { "a1", "a2", "a3" };
var result = db.Products.ToList().Where(p => searchs.Any(s => p.Content.Contains(s))).ToList();
The result on my side as below:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion