0

i want to make it straight forward because i tried a lot of stuff and none of them seems to work for me.

Categories = await  _context.Categories.ToListAsync(),
            CategorySubjects = await _context.CategorySubjects
            .Include(s => s.Books.Where( == true))
            .ToListAsync(),
Books = await _context.Books.Where(b => b.Active == true).ToListAsync()

I have this piece of code where i want to get all categorysubjects with all books in them where the active of book is true and this is the equivalent of it in sql

select *
from CategorySubjects
    left join Books on  CategorySubjects.Id = Books.CategorySubjectId
where Books.Active = 1

Thanks.

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • That LEFT JOIN returns regular INNER JOIN result anyway... Move the Books.Active condition from WHERE to ON to get true LEFT JOIN result. (Simply replace WHERE with AND.) – jarlh Feb 14 '19 at 13:21
  • Yes i get that in sql, but i cant get the result in c# –  Feb 14 '19 at 13:32
  • https://stackoverflow.com/questions/3404975/left-outer-join-in-linq – jarlh Feb 14 '19 at 13:35
  • Perhaps my [SQL to LINQ Recipe](https://stackoverflow.com/questions/49245160/sql-to-linq-with-multiple-join-count-and-left-join/49245786#49245786) could help you? – NetMage Feb 14 '19 at 22:32

0 Answers0