下面的查询代码
DateTime startTime = DateTime.Now.Date;
var query = ExistingPosts(blogId).Where(p => p.DatePublished >= startTime);
var count = await query.CountAsync();
对应的 EF Core 日志
2025-12-12 12:23:42.920 [Information] Executed DbCommand ("6"ms) [Parameters=["@blogId='40823', @startTime='2025-12-12T00:00:00.0000000+08:00'"], CommandType='Text', CommandTimeout='15']"
""SELECT COUNT(*)
FROM [blog_posts] AS [b]
WHERE [b].[BlogId] = @blogId AND [b].[IsExist] = CAST(1 AS bit) AND [b].[DateAdded] >= @startTime"
SQL 的 @startTime 参数被 EF Core 自动加上了时区 +08:00 ,请问如何不让 EF Core 这么干?
用的是 .NET 10
是我弄错了,@startTime 参数带上时区 +08:00 没有问题
DateTime.UtcNow
或者配置DbContext的时候加一个conversion.==> DateTime.SpecifyKind(d, UTC) 改Kind到UTC.
说明liunx的默认时区是太平洋时区, 我都是liunx系统改成上海时区的
容器里的 linux 系统是上海时区