I would like to know how to write the following SQL query in Linq. I’ve tried but without luck.
/*Variable*/
topicId = '4a31c2ee-48af-4b87-b300-112acb822ad0'
select * from Contents c
left join ContentToTopicRelations ctr on ctr.ContentId = c.ContentId and ctr.TopicId = topidId
where ctr.ContentId is null
Basically, I would like to get all the contents that are not in ContentToTopicRelations table for a particular topicId.
It is identical to
select * from Content where not exists(...). And in general case it is better than left join and checking for null (it depends on the table statistics but..), because it will give (again, in general case) semi left join instead of left join (in the execution plan).For left join itself use code like following (but I recommend using code which generates
not existsfor your task):