How to write this SQL query in Linq To SQL -


i know how write following sql query in linq. i've tried without luck.

/*variable*/ topicid = '4a31c2ee-48af-4b87-b300-112acb822ad0'  select * contents c left join contenttotopicrelations ctr on ctr.contentid = c.contentid , ctr.topicid = topidid ctr.contentid null 

basically, contents not in contenttotopicrelations table for particular topicid.

 datacontext.contents.where(c =>   !datacontext.contenttotopicrelations.any(ctr =>      ctr.contantid == c.contentid &&      ctr.topicid == topicid)) 

it identical select * content not exists(...). , in general case better left join , checking null (it depends on table statistics but..), because give (again, in general case) semi left join instead of left join (in execution plan).

for left join use code following (but recommend using code generates not exists task):

 c in datacontext.contents join tempctr in datacontext.contenttotopicrelations   on new { c.contentid, topicid) equals new { tempctr.contentid, tempctr.topicid }   tempctrcollection   ctr in tempctrcollection.defaultifempty() ctr == null select c 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -