title: if-else clause in Linq to entity framework query
body: <p>Following Linq to Entities query is causing the "Unable to create a constant value of type 'Data.InhouseUnit'. Only primitive types ('such as Int32, String, and Guid') are supported in this context" exception.</p>
  
  <pre><code>IList&lt;FaultReport&gt; faultReports = (from fr in _session.FaultReports
     where fr.CreatedOn &gt; dateTime
     select new FaultReport
     {
         Id = fr.Id,
         ExecutionDate = fr.ExecutionDate ?? DateTime.MinValue,
         FaultType = fr.FaultType,
         Quarters = fr.Quarters,
         InhouseSpaceId = fr.InhouseSpaceId,
         InhouseSpace = new InhouseSpace { Id = fr.InhouseSpace.Id, Name = fr.InhouseSpace.Name },
         InhouseUnitId = fr.InhouseUnitId ?? Guid.Empty,
         **InhouseUnit = fr.InhouseUnitId == Guid.Empty ? null : new InhouseUnit { Id = fr.InhouseUnit.Id, Name = fr.InhouseUnit.Name }**
  }).ToList();
  </code></pre>
  
  <p>Specifically, it is the if expression in bold font which causes the exception. I need to make the check as fr.InhouseUnitId is a nullable. If I take out the the bolded expression, the rest of the statement works just fine. I have spent a fair amount of time, in msdn forum and on web, to understand what is causing the exception but still cannot quite understand. Guid is scalar so it should work, right? Even this expression <code>InhouseUnit = true ? null: new InhouseUnit()</code> in place of the bolded expression in the above statement wouldn't work. Can we even write if/else</p>
  
  <p>If i try to write an extension method to take away the logic and just return a result, following exception is thrown:</p>
  
  <pre><code>LINQ to Entities does not recognize the method 'System.Object 
  GuidConversion(System.Nullable`1[System.Guid], System.Object)' method, and this method 
  cannot be translated into a store expression
  </code></pre>