Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to do inner join and right outer join in the same query
    primarykey
    data
    text
    <p>I have these 3 tables:</p> <ol> <li>FeatureTbl (FeatureId (PK),FeatureName)</li> <li>ParameterTbl (ParameterId (PK),ParameterName)</li> <li>Map_Parameter_To_Feature (MapId (PK),FeatureId(FK),ParameterId(FK))</li> </ol> <p>I want to convert the following SQL to LINQ:</p> <pre class="lang-sql prettyprint-override"><code>SELECT FeatureTbl.FeatureId, FeatureTbl.FeatureName, Map_Parameter_To_Feature.ParameterId, ParameterTbl.ParameterName FROM ParameterTbl INNER JOIN Map_Parameter_To_Feature ON ParameterTbl.ParameterId = Map_Parameter_To_Feature.ParameterId RIGHT OUTER JOIN FeatureTbl ON Map_Parameter_To_Feature.FeatureId = FeatureTbl.FeatureId </code></pre> <p>The above query returns the following result</p> <pre class="lang-none prettyprint-override"><code>FeatureId,FeatureName,ParameterId,ParameterName 1 Feat A NULL NULL 2 Feat B 10 Param X 3 Feat B 10 Param Y 4 Feat C NULL NULL </code></pre> <p>I wrote the following LINQ:</p> <pre class="lang-csharp prettyprint-override"><code>(from p in context.ParameterTbls join mp2f in context.Map_Parameter_To_Feature on p.ParameterId equals mp2f.ParameterId join f in context.FeatureTbls on mp2f.FeatureId equals f.FeatureId into desiredresult from r in desiredresult.DefaultIfEmpty() select new { r.FeatureId, r.FeatureName, mp2f.ParameterId, p.ParameterName }); </code></pre> <p>But I get this result</p> <pre class="lang-none prettyprint-override"><code>FeatureId,FeatureName,ParameterId,ParameterName 2 Feat B 10 Param X 3 Feat B 10 Param Y </code></pre> <p>How can I convert the above SQL to LINQ?</p>
    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