我正在使用LINQ来查询来自多个表的数据。
var test= await _context.Article
.Select(a => new
{
a.ID,
a.Title,
a.CreatedTime,
a.EditedTime,
a.Author.UserName,
a.AuthorID
}).ToListAsync();
Author
是Article
类中的导航属性。
但我从日志中得到了这个:
Executed DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [a].[ID], [a].[AuthorID], [a].[Content], [a].[CreatedTime], [a].[EditedTime], [a].[Title], [a.Author].[Id], [a.Author].[AccessFailedCount], [a.Author].[ConcurrencyStamp], [a.Author].[Email], [a.Author].[EmailConfirmed], [a.Author].[LockoutEnabled], [a.Author].[LockoutEnd], [a.Author].[NormalizedEmail], [a.Author].[NormalizedUserName], [a.Author].[PasswordHash], [a.Author].[PhoneNumber], [a.Author].[PhoneNumberConfirmed], [a.Author].[SecurityStamp], [a.Author].[TwoFactorEnabled], [a.Author].[UserName]
FROM [Article] AS [a]
LEFT JOIN [AspNetUsers] AS [a.Author] ON [a].[AuthorID] = [a.Author].[Id]
ORDER BY [a].[AuthorID]
我只想要一些字段,但它会查询所有字段。如果我从代码中删除a.Author.UserName
行,它就会按预期工作。
我错过了什么吗?
我正在使用Entity Framework Core 1.1.0和Microsoft SQL Server。