【问题标题】:How to make Entity Framework Core query some of the fields when performing JOIN执行 JOIN 时如何让 Entity Framework Core 查询某些字段
【发布时间】:2017-01-16 21:27:47
【问题描述】:

我正在使用 LINQ 从多个表中查询数据。

var test= await _context.Article
.Select(a => new
{
    a.ID,
    a.Title,
    a.CreatedTime,
    a.EditedTime,
    a.Author.UserName,
    a.AuthorID
}).ToListAsync();

AuthorArticle 类中的导航属性。

但我是从日志中得到的:

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 一起使用。

【问题讨论】:

    标签: c# entity-framework linq entity-framework-core


    【解决方案1】:

    此行为已经是 documented as bug,计划在里程碑 2.0.0 中修复

    【讨论】:

    • 酷。现在“唯一”的问题是 2.0.0 何时到来,以及在此之前人们应该如何处理所有这些错误 :)
    猜你喜欢
    • 2020-09-02
    • 1970-01-01
    • 2022-01-25
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多