【问题标题】:Entity Framework force inner join with thenInclude实体框架强制内部加入 thenInclude
【发布时间】:2021-02-11 12:28:09
【问题描述】:

我的 EF 框架查询如下

.Include( d => d.Photos)
  .ThenInclude( p => p.File )

这会在文件表上生成一个带有外部连接的 mysql 查询。我得到如下查询

Select * from
photos as p
INNER JOIN (
 SELECT f.id
 FROM files AS f
) AS t40 ON p.file_id = t40.id

如何确保有如下查询?单行的原因是因为上面的查询没有使用主键索引,查询上的性能很高

Select * from
photos as p
INNER JOIN files as f on p.file_id = f.id

【问题讨论】:

    标签: entity-framework


    【解决方案1】:

    EF 将根据包含的链接的可空性决定是使用内连接还是左连接。 您应该检查表格照片/文件关系。 在此答案中查找更多信息! Entity framework Include command - Left or inner join?

    【讨论】:

    • 谢谢,这很有帮助。我可以获得内部连接,但是否有可能获得单线连接。我已经更新了我的问题
    • 您能发布您的完整查询吗?你试过类似(from p in _context.Photos join f in _context.File on p.file_id equals f.Id select new { PID = p.id, FID = f.id, (keep on going) }).ToList();
    猜你喜欢
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多