【发布时间】:2019-11-11 19:59:14
【问题描述】:
将 ef core 更新到 3.0 后,当尝试截断时间并仅比较 datetime 中的日期时,ef core 返回错误:
The LINQ expression 'Where<Category>(\n source: DbSet<Category>, \n predicate: (c) => c.CreateAt.Date == DateTime.Now.Date)' 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.
对于这个查询:
Context.Category.Where(c => c.CreateAt.Date == DateTime.Now.Date).AsNoTracking().ToListAsync();
我只需要比较日期,而忽略 DateTimeOffSet 属性中的时间。
【问题讨论】:
标签: c# asp.net-core .net-core .net-core-3.0 ef-core-3.0