【问题标题】:Entity Framework Join inner Include实体框架加入内部包含
【发布时间】:2020-02-23 21:31:30
【问题描述】:

怎么了?

var tests = _repo.Tests.Include(a => a.Answers.Join(_repo.Questions, answer => answer.QuestionNumber, question => question.QuestionNumber, (answer, question) => new { Answer = answer, Question = question })).Where(u => u.User.UserName == username);

错误 CS0411:无法从用法中推断方法“Enumerable.Join(IEnumerable, IEnumerable, Func, Func, Func)”的类型参数。尝试明确指定类型参数。

【问题讨论】:

  • 编译器可能试图告诉你一个异常。如果没有例外,而您只是没有看到您认为应该看到的内容,那么您告诉我们出了什么问题。 :)

标签: entity-framework join include


【解决方案1】:

您可以像这样使用 ThenInclude 加入其他表。

var tests = _repo.Tests
    .Include(a => a.Answers)
      .ThenInclude(q => q.Questions)
    .Where(u => u.User.UserName == username)
    .ToList();

【讨论】:

    猜你喜欢
    • 2010-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多