小编She*_*jid的帖子

无法翻译 LINQ 表达式。要么以可翻译的形式重写查询,要么切换到客户端评估

我有 C# 应用程序 (.NET Core 3.1),并且编写了以下 LINQ 表达式。

public ActionResult<bool> GetItems(string title)
{
     var items = _service.All.GetItems().OrderByDescending(o => o.Id).Where(w => w.Portal_Id == 1);

     if (!string.IsNullOrWhiteSpace(title))
     {
            var terms = title.Split(' ').ToList();
            items = items.Where(w => terms.Any(a => w.ItemName.Contains(a)));
     }
     // Some Other code
     return Ok();
}
Run Code Online (Sandbox Code Playgroud)

每当执行此表达式时,我都会收到以下错误

The LINQ expression 'DbSet<PosItem>\r\n    .Where(p => !(p.IsDeleted))\r\n    
.OrderByDescending(p => p.CreatedAt)\r\n    .Where(p => p.Portal_Id == 1)\r\n    .Where(p => __terms_1\r\n      
.Any(a => p.ItemName.Contains(a)))' could not be translated.

Either rewrite the query in a form that …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework .net-core

33
推荐指数
1
解决办法
12万
查看次数

标签 统计

.net-core ×1

c# ×1

entity-framework ×1

linq ×1