C# 实体框架核心-为每行生成sql select
我使用EF Core 1.1.2。我有这个疑问:C# 实体框架核心-为每行生成sql select,c#,entity-framework-core,C#,Entity Framework Core,我使用EF Core 1.1.2。我有这个疑问: var tmp = _context.Notes .Select(x => new { Note = x, CommentsCount = x.Comments.Count(y => y.Status == 1) }).ToList(); 我想对数据库进行一次查询,但每个注释都有很多查询: SELE
var tmp = _context.Notes
.Select(x => new
{
Note = x,
CommentsCount = x.Comments.Count(y => y.Status == 1)
}).ToList();
我想对数据库进行一次查询,但每个注释都有很多查询:
SELECT [x].[NoteId], [x].[Content], [x].[Title]
FROM [Notes] AS [x]
exec sp_executesql N'SELECT COUNT(*)
FROM [Comments] AS [y1]
WHERE ([y1].[Status] = 1) AND (@_outer_NoteId = [y1].[NoteId])',N'@_outer_NoteId int',@_outer_NoteId=13
exec sp_executesql N'SELECT COUNT(*)
FROM [Comments] AS [y1]
WHERE ([y1].[Status] = 1) AND (@_outer_NoteId = [y1].[NoteId])',N'@_outer_NoteId int',@_outer_NoteId=14
// and much more for each note
这是EF Core 1.1.2中的一个bug吗?如何设置实体?fluent api或数据注释数据注释扫描您如何显示实体的设置?您的LINQ查询有效吗?是的(我会说这是非常基本的)。因此,是的,这是一个错误。