Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ LEFT JOIN With a LIST<String>
    primarykey
    data
    text
    <p>Say you have a list of IDs: </p> <pre><code>string str = "82174F2000000, 82174F2000001, 82174F2000002, 82174F2000003, 82174F2000004, 82174F2000005"; </code></pre> <p>And you do this:</p> <pre><code>var tids = new List&lt;string&gt;(str.Replace(", ", ",").Split(',')); var tntable = tids.AsQueryable(); </code></pre> <p>And you want to compare it to a table with a Left Join:</p> <pre><code>var line = from c in db.Ctable join l in tntable on c.CarID equals l.CarID into c_j from l in c_j.DefaultIfEmpty() select new { Name = c.OwnerName, Hours = c.Hours }; </code></pre> <p>looks like the tntable doesn't have a field called 'CarID'.</p> <p>Can someone please help?</p> <p>This is for LINQ to Entity.</p> <p>I have seen this:</p> <p><a href="https://stackoverflow.com/questions/3922619/how-to-compare-liststring-to-db-table-using-linq">How to compare List&lt;String&gt; to DB Table using LINQ</a></p> <p>But don't know to do a LEFT JOIN. </p> <p>TIA!</p> <p>I know this is long; but thanks for reading.</p> <p><strong>UPDATED FOR MichaC:</strong></p> <p>In the database in CTable we have these CarIDs:</p> <pre><code>CarID _____ 82174F2000000 82174F2000001 82174F2000002 82174F2000003 </code></pre> <p>Let's just say the table (tntable) contains the string broken down into records:</p> <pre><code>CarID _____ 82174F2000000 82174F2000001 82174F2000002 82174F2000003 82174F2000004 82174F2000005 </code></pre> <p>So, a LEFT JOIN like this:</p> <pre><code>SELECT C.CarID, T.CarID FROM CTable C LEFT JOIN tntable T ON C.CarID = T.CarID </code></pre> <p>Will yield you this:</p> <pre><code>T.CarID C.CarID _______ _______ 82174F2000000 82174F2000000 82174F2000001 82174F2000001 82174F2000002 82174F2000002 82174F2000003 82174F2000003 82174F2000004 NULL 82174F2000005 NULL </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload