Left outer join of 2 datatables
<p>I want to left join 2 data tables <code>AllTimesTxnTable</code> and <code>resolvedDt</code> in C#, Where I want every row from AllTimesTxnTable and only matching rows from resolvedDt. </p>

<p>The join condition should be based on <code>mid</code> and <code>txndate</code> and finally while selecting <strong>I want mid and txndate from AllTimesTxnTable and txncount from resolvedDt, if no record in resolvedDt then a 0.</strong></p>

<p>I tried the following LINQ query:</p>

<pre><code> var results = from table2 in AllTimesTxnTable.AsEnumerable()
               join table1 in resolvedDt.AsEnumerable()
               on new { mid = table2.Field&lt;int&gt;("mid"), txndate = table2.Field&lt;string&gt;("txndate") } equals new { mid = table1.Field&lt;int&gt;("mid"), txndate = table1.Field&lt;string&gt;("txndate") }
               into temp
               from leftTable in temp.DefaultIfEmpty()
               select new
               {
                    MId = (int)table2["mid"],
                    TxnDate = (string)table2["txndate"],
                    TxnCount = leftTable["txncount"] == null ? 0M : (decimal)leftTable["txncount"]
                };
</code></pre>

<p>But it gives me an Error: <code>Object reference not set to an instance of an object.</code> while selecting. </p>

<p>Not getting whats going wrong here. </p>