Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法翻译C Linq表达式_C#_Entity Framework_Linq_Entity Framework Core_.net Core 3.0 - Fatal编程技术网

C# 无法翻译C Linq表达式

C# 无法翻译C Linq表达式,c#,entity-framework,linq,entity-framework-core,.net-core-3.0,C#,Entity Framework,Linq,Entity Framework Core,.net Core 3.0,我正在尝试执行linq查询,以获取所有具有特定技能的员工。search.skills是一个包含一些技能的字符串列表,我想检索所有具有这些技能和条件的用户。 在关于员工的my where子句中,exp.Skills是ICollection,expSkill.SkillName是技能名称 .Where( emp => search.Skills.All( searchSkill =>

我正在尝试执行linq查询,以获取所有具有特定技能的员工。search.skills是一个包含一些技能的字符串列表,我想检索所有具有这些技能和条件的用户。 在关于员工的my where子句中,exp.Skills是ICollection,expSkill.SkillName是技能名称

                .Where(
                emp => search.Skills.All(
                    searchSkill => emp.Experiences.Select(exp => exp.Skills).SelectMany(x => x).Select(expSkill => expSkill.SkillName).Contains(searchSkill)
                ))
            .ToListAsync();
我在尝试执行时遇到以下错误。我正在使用entityframework core 3

The LINQ expression 'DbSet<Employee>
.Where(e => __search_Skills_0
    .All(searchSkill => DbSet<Experience>
        .Where(e0 => EF.Property<Nullable<Guid>>(e, "Id") != null && EF.Property<Nullable<Guid>>(e, "Id") == EF.Property<Nullable<Guid>>(e0, "EmployeeId"))
        .SelectMany(
            source: e0 => DbSet<ExperienceSkill>
                .Where(e1 => EF.Property<Nullable<Guid>>(e0, "EmployeeId") != null && new AnonymousObject(new object[]
                { 
                    (object)EF.Property<Nullable<Guid>>(e0, "EmployeeId"), 
                    (object)EF.Property<string>(e0, "ProjectCode") 
                }) == new AnonymousObject(new object[]
                { 
                    (object)EF.Property<Nullable<Guid>>(e1, "ExperienceEmployeeId"), 
                    (object)EF.Property<string>(e1, "ExperienceProjectCode") 
                })), 
            collectionSelector: (e0, c) => new TransparentIdentifier<Experience, ExperienceSkill>(
                Outer = e0, 
                Inner = c
            ))
        .Select(ti => ti.Inner.SkillName)
        .Contains(searchSkill)))' 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.

有人能告诉我我的问题出在哪里吗?谢谢

EF Core目前无法翻译LINQ运算符,只能翻译内存集合(如search.Skills)上的简单包含

因此,您需要找到memoryCollection.All运算符的替代方法。在这种情况下,我使用的是计数匹配方法,它查找所有匹配的记录并比较不同值的计数

e、 g.更换

emp => search.Skills.All(
    searchSkill => emp.Experiences.Select(exp => exp.Skills).SelectMany(x => x).Select(expSkill => expSkill.SkillName).Contains(searchSkill)


错误是:要么以可以翻译的形式重写查询,要么通过插入对AsEnumerable、AsAsAsAsyncEnumerable、ToList或ToListSync的调用显式切换到客户端计算。IEnumerable vs iquierable,在EF中很难扭转你的思维。我将尝试找到一个参考问题,以便对我看到你的.ToListSync;不包括在错误消息中,从缩进判断,它应用于查询的外部部分。也许可以尝试直接在where子句上应用一个?我正在应用。ToListSync;在where子句可能与相关的。我们可以看一下类贴花吗?ID是作为GUID、int还是字符串存储在数据库中的?
emp => emp.Experiences
    .SelectMany(exp => exp.Skills, (exp, skill) => skill.SkillName)
    .Where(skillName => search.Skills.Contains(skillName))
    .Distinct().Count() == search.Skills.Distinct().Count()