0

I have my EF framework query as below

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

This produces a mysql query with outer join on file table. I get query as below

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

How can I ensure to have query as below? The reason to have a single line is because the above query does not use primary key index and the performance on the query is very high

Select * from
photos as p
INNER JOIN files as f on p.file_id = f.id
user2837961
  • 1,505
  • 3
  • 27
  • 67

1 Answers1

1

EF will decide whether to use inner join or left join depending Include depending on the nullability of the included link. You should have to check table Photos/File relationship. Find more info in this answer ! Entity framework Include command - Left or inner join?

Nahue Gonzalez
  • 273
  • 4
  • 10
  • Thanks this is helpful. I can get inner join but is it possible to get single line join. I have updated my question – user2837961 Feb 11 '21 at 14:40
  • Could you post your full query ? Have you tried something like `(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();` – Nahue Gonzalez Feb 11 '21 at 21:01