简体   繁体   English

是什么导致此查询在 EF Core 3.x 中无法翻译?

[英]What makes this query untranslatable in EF Core 3.x?

I have a simple model and query:我有一个简单的 model 和查询:

public class Item
{
    public String Name { get; set; }

    public Boolean Complete { get; set; }
}

List<Item> lstIncompleteItems = await context.Items.Where(currentItem => currentItem.Complete == false).ToListAsync();

This results in the "could not be translated" exception.这导致“无法翻译”异常。 I've read about the breaking changes when moving from EF Core 2.x to 3.x but I think something has failed to register in my brain about it.我已经阅读了从 EF Core 2.x 迁移到 3.x 时发生的重大变化,但我认为我的大脑中有一些东西未能记录下来。 Just trying to understand exactly how to write my queries in translatable format.只是想确切地了解如何以可翻译的格式编写我的查询。

What is it that makes the above query untranslatable, while the following works perfectly fine?是什么使上面的查询无法翻译,而下面的查询却完美无缺?

List<Item> lstItems = await context.Items.Where(currentItem => currentItem.Name.Contains("something")).ToListAsync();

The Complete property of the Item may be marked as internal in your code, you can change it to public to be able to use it in queries. ItemComplete属性可能在您的代码中标记为内部,您可以将其更改为公共以便能够在查询中使用它。

public class Item
{
    public String Name { get; set; }
    public Boolean Complete { get; set; }
}

Also double check the where import if it uses the correct LINQ method.如果它使用正确的 LINQ 方法,还要仔细检查 where 导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM