实体框架CORE - 为每一行生成sql select

时间:2017-05-20 18:41:02

标签: 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();

我想对数据库进行一次查询,但每张注释都有很多:

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中的错误吗?

0 个答案:

没有答案