Note that there are some explanatory texts on larger screens.

plurals
  1. POLeft join is not working for complex query
    primarykey
    data
    text
    <p>I have very complex linq query which is working fine for inner join, i.e., without <code>z_temp.DefaultIfEmpty()</code>. But when I use this for left join, The query is not yielding results.</p> <pre><code>var q = from x in db.EmployeesList where x.EmployeesListStartDate &gt;= startDate &amp;&amp; x.EmployeesListStartDate &lt;= endDate join y in db.Survey on x.Survey.SurveyID equals y.SurveyID join z in (from a in db.Commit join b in (from commit in db.Commit where commit.CommitListID != null &amp;&amp; commit.CommitType.ToUpper() != "PREVIEW" group commit by new { commit.CommitListID } into g select new { CommitListID = (Int32?)g.Key.CommitListID, CommitId = (Int32?)g.Max(p =&gt; p.CommitId) }) on new { a.CommitListID, a.CommitId } equals new { b.CommitListID, CommitId = (Int32)b.CommitId } select new { CommitListID = (Int32?)a.CommitListID, CommitUsername= a.CommitUsername, CommitStartDateTime=a.CommitStartDateTime, CommitType=a.CommitType, CommitSuccessCount=a.CommitSuccessCount }) on new { EmployeesListID = x.EmployeesListID } equals new { EmployeesListID = (Int32)z.CommitListID } into z_temp from _z in z_temp.DefaultIfEmpty() select new CustomEmployeesList { SurveyId = x.Survey.SurveyID != null ? (int)x.Survey.SurveyID : 0, EmployeesListId = x.EmployeesListID != null ? (int)x.EmployeesListID : 0, EmployeesListName = x.EmployeesListName, SpecificMessage = x.SpecificMessage, ListCriteria = x.ListCriteria, Channel = x.Channel, EmployeesListStartDate = (DateTime)x.EmployeesListStartDate, EmployeesListEndDate = (DateTime)x.EmployeesListEndDate, Records = x.Records != null ? (int)x.Records : 0, QueryId = x.AppSqlQueries.QueryId != null ? (int)x.AppSqlQueries.QueryId : 0, //AuditId = (Int32?)x.AuditEntry.AuditId, StatusCommonCode = x.CommonCode.CommonCodeId != null ? (int)x.CommonCode.CommonCodeId : 0, SurveyName = y.SurveyName, LastCommitDateTime = _z.CommitStartDateTime.HasValue ? (DateTime)_z.CommitStartDateTime : DateTime.MinValue, LastCommitType = _z.CommitType != null ? _z.CommitType : "", LastCommitUsername = _z.CommitUsername != null ? _z.CommitUsername : "", LastCommitCount = _z.CommitSuccessCount.HasValue ? (int)_z.CommitSuccessCount : 0 }; </code></pre> <p>This is returning no results and I am getting this exception message while viewing results in debug mode:</p> <blockquote> <p>LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable1[&lt;>f_<em>AnonymousType351[&lt;>f</em>_AnonymousType35%5bSystem.Nullable1[System.Int32],System.String,System.Nullable1%5bSystem.DateTime%5d,System.String,System.Nullable`1%5bSystem.Int32%5d%5d%5d">System.Nullable1[System.Int32],System.String,System.Nullable1[System.DateTime],System.String,System.Nullable1[System.Int32]]] DefaultIfEmpty[&lt;>f__AnonymousType35' method, and this method cannot be translated into a store expression.</p> </blockquote> <p>Can anyone suggest the where the problem would be, this would be really helpful!</p>
    singulars
    1. This table or related slice is empty.
    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