Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In Lambda :</p> <pre><code> var persons = Persons.Where(p=&gt;(p.PersonLocations.Select(ps=&gt;ps.Location) .Where(l=&gt;l.Description == "Amsterdam").Count() &gt; 0) &amp;&amp; (p.PersonRoles.Select(pr=&gt;pr.Role) .Where(r=&gt;r.Description == "Student").Count() &gt; 0)); </code></pre> <p><strong>query result:</strong></p> <pre><code>SELECT [t0].[personId] AS [PersonId], [t0].[description] AS [Description] FROM [Persons] AS [t0] WHERE ((( SELECT COUNT(*) FROM [personlocations] AS [t1] INNER JOIN [Locations] AS [t2] ON [t2].[locationid] = [t1].[locationid] WHERE ([t2].[description] = @p0) AND ([t1].[personid] = [t0].[personId]) )) &gt; @p1) AND ((( SELECT COUNT(*) FROM [PersonRoles] AS [t3] INNER JOIN [Roles] AS [t4] ON [t4].[roleid] = [t3].[roleid] WHERE ([t4].[description] = @p2) AND ([t3].[personid] = [t0].[personId]) )) &gt; @p3) </code></pre> <p><strong>Using Contains():</strong></p> <pre><code>var persons = Persons .Where(p=&gt;(p.Personlocations.Select(ps=&gt;ps.Location) .Select(l=&gt;l.Description).Contains("Amsterdam")) &amp;&amp; (p.PersonRoles.Select(pr=&gt;pr.Role) .Select(r=&gt;r.Description).Contains("Student"))); </code></pre> <p><strong>query result:</strong></p> <pre><code>SELECT [t0].[personId] AS [PersonId], [t0].[description] AS [Description] FROM [Persons] AS [t0] WHERE (EXISTS( SELECT NULL AS [EMPTY] FROM [personlocations] AS [t1] INNER JOIN [Locations] AS [t2] ON [t2].[locationid] = [t1].[locationid] WHERE ([t2].[description] = @p0) AND ([t1].[personid] = [t0].[personId]) )) AND (EXISTS( SELECT NULL AS [EMPTY] FROM [PersonRoles] AS [t3] INNER JOIN [Roles] AS [t4] ON [t4].[roleid] = [t3].[roleid] WHERE ([t4].[description] = @p1) AND ([t3].[personid] = [t0].[personId]) )) </code></pre> <p><strong>using join():</strong></p> <pre><code>var persons = Persons .Join(Personlocations, p=&gt;p.PersonId, ps=&gt;ps.Personid, (p,ps) =&gt; new {p,ps}) .Where(a =&gt; a.ps.Location.Description =="Amsterdam") .Join(PersonRoles, pr=&gt; pr.p.PersonId, r=&gt;r.Personid,(pr,r) =&gt; new {pr.p,r}) .Where(a=&gt;a.r.Role.Description=="Student") .Select(p=&gt; new {p.p}); </code></pre> <p>Query Result:</p> <pre><code>SELECT [t0].[personId] AS [PersonId], [t0].[description] AS [Description] FROM [Persons] AS [t0] INNER JOIN [personlocations] AS [t1] ON [t0].[personId] = [t1].[personid] INNER JOIN [Locations] AS [t2] ON [t2].[locationid] = [t1].[locationid] INNER JOIN [PersonRoles] AS [t3] ON [t0].[personId] = [t3].[personid] INNER JOIN [Roles] AS [t4] ON [t4].[roleid] = [t3].[roleid] WHERE ([t4].[description] = @p0) AND ([t2].[description] = @p1) </code></pre> <p>You may want test wich one is faster with large data.</p> <p>Good luck.</p> <p>Giuliano Lemes</p>
 

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