小编mon*_*see的帖子

从dotnet Core 2.2.6更改为3.0.0后的EF Linq错误

我正在尝试将解决方案升级到新的Core Framework 3.0.0。现在我有一个小问题,我不明白。

看,此方法在2.2.6中没有问题:

public async Task<IEnumerable<ApplicationUser>> GetBirthdayUsersCurrentMonth()
    {
        return await ApplicationDbContext.Users
            .Where(x => x.Gender != ApplicationUser.GenderTypes.generic)
            .Where(x => x.BirthDate.GetValueOrDefault().Month == DateTime.Now.Month)
            .Where(x => x.RetireDate == null)
            .OrderBy(x => x.BirthDate.GetValueOrDefault())
            .ToListAsync();
    }
Run Code Online (Sandbox Code Playgroud)

现在在3.0.0中,我收到一个Linq错误,它是这样说的:

InvalidOperationException:LINQ表达式'Where(source:where(source:DbSet,predicate:(a)=>(int)a.Gender!= 0),谓词:(a)=> a。 == DateTime.Now.Month)'无法翻译。以可以翻译的形式重写查询,或者通过插入对AsEnumerable(),AsAsyncEnumerable(),ToList()或ToListAsync()的调用来显式切换到客户端评估

当我禁用此行时:

.Where(x => x.BirthDate.GetValueOrDefault().Month == DateTime.Now.Month)
Run Code Online (Sandbox Code Playgroud)

错误消失了,但是我当然会吸引所有用户。而且我在此查询中看不到错误。这可能是EF Core 3.0.0中的错误吗?

c# .net-core entity-framework-core-3.0

6
推荐指数
2
解决办法
2280
查看次数

标签 统计

.net-core ×1

c# ×1

entity-framework-core-3.0 ×1