Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I know this question it's old, but I think it's need a correct answer, I get to this questing searching for a LINQ equivalent of the IN SQL Keyword and see that the equivalent LINQ code for this query are not provided, maybe the Original author answer this question some time ago, but I leave this for other people searching in the internet:</p> <p>I got to answers one if you like to have Left Outer Joins:</p> <pre><code>var query = from emp in context.Persons join ter in context.Terminations on emp.Id equals ter.IdPerson into terminations join dep in context.Departments on emp.IdDeparment equals dep.IdDepartment into departments join job in context.Jobs on emp.IdJob equals job.IdJob into jobs from ter in terminations.DefaultIfEmpty() //Does an Left Outer Join from dep in departments.DefaultIfEmpty() from job in jobs.DefaultIfEmpty() where (ter.IdTermination == null || ter.TerminationDate &gt;= period) &amp;&amp; (ter.HireDate &lt;= period || emp.HireDate &lt;=period) select new { emp.Id, emp.Name, emp.PaternalName, dep.DepartmentName, job.Title, emp.HireDate, ter.TerminationDate, TerminationHireDate=ter.HireDate }; </code></pre> <p>one using Inner Joins</p> <pre><code> var query = from emp in context.Persons join ter in context.Terminations on emp.Id equals ter.IdPerson join dep in context.Departments on emp.IdDeparment equals dep.IdDepartment join job in context.Jobs on emp.IdJob equals job.IdJob where (ter.IdTermination == null || ter.TerminationDate &gt;= period) &amp;&amp; (ter.HireDate &lt;= period || emp.HireDate &lt;=period) select new { emp.Id, emp.Name, emp.PaternalName, dep.DepartmentName, job.Title, emp.HireDate, ter.TerminationDate, TerminationHireDate=ter.HireDate }; </code></pre> <p>the variable context is the Linq to SQL or Linq to Entity Context</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.
    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