1
我使用LINQ從多個表中查詢數據。如何使Entity Framework Core在執行JOIN時查詢一些字段
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
行,它只是按預期工作。
我錯過了什麼嗎?
我正在使用實體框架核心1.1.0與Microsoft SQL Server。
很酷。現在「唯一」的問題是2.0.0何時到來,以及人們應該如何處理所有這些錯誤:) –