EF核心包括在数据之间
我正在将ASP.NET Core与实体框架Core一起使用,并且正在尝试在特定的DateTime框架内过滤结果。
这是我的dbContext查询:
var device = await _context.Devices.Where(d => d.Id == id)
.Include(d => d.Layouts.Where(i => i.CreatedAt > fromDateTime && i.CreatedAt < toDateTime))
.ThenInclude(a => a.States)
.FirstOrDefaultAsync();
'CreateAt'在SQL Server中的“ DateTime”格式中,“ FromDateTime”和“ TodateTime”也是DateTime类型。
直接查询基本上是即时的:
SELECT * [Id]
,[CreatedAt]
FROM [Layout]
Where CreatedAt > '2022-07-03 00:00:00'
And CreatedAt < '2022-07-04 00:00:00'
但是从后端开始,我花了很长时间,我没有等到完成,而是20分钟。
我需要帮助才能找到我在做错什么,或者如何编写查询以使其更快。 谢谢。
I am using ASP.NET CORE with Entity Framework Core and I am trying to filter out result within a specific DATETIME frame.
This is my DBContext query:
var device = await _context.Devices.Where(d => d.Id == id)
.Include(d => d.Layouts.Where(i => i.CreatedAt > fromDateTime && i.CreatedAt < toDateTime))
.ThenInclude(a => a.States)
.FirstOrDefaultAsync();
'CreatedAt' is in 'datetime' format in the SQL Server, 'fromDateTime' and 'toDateTime' is also DateTime type.
The direct query is basically instant:
SELECT * [Id]
,[CreatedAt]
FROM [Layout]
Where CreatedAt > '2022-07-03 00:00:00'
And CreatedAt < '2022-07-04 00:00:00'
But from the backend it takes very long, I did not wait until if finishes but more 20 minutes.
I would need help to find what I am doing wrong or how can I write the query to be faster.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)