Note that there are some explanatory texts on larger screens.

plurals
  1. POcount on LINQ union
    primarykey
    data
    text
    <p>I'm having this link statement:</p> <pre><code>List&lt;UserGroup&gt; domains = UserRepository.Instance.UserIsAdminOf(currentUser.User_ID); query = (from doc in _db.Repository&lt;Document&gt;() join uug in _db.Repository&lt;User_UserGroup&gt;() on doc.DocumentFrom equals uug.User_ID where domains.Contains(uug.UserGroup) select doc) .Union(from doc in _db.Repository&lt;Document&gt;() join uug in _db.Repository&lt;User_UserGroup&gt;() on doc.DocumentTo equals uug.User_ID where domains.Contains(uug.UserGroup) select doc); </code></pre> <p>Running this statement doesn't cause any problems. But when I want to count the resultset the query suddenly runs quite slow.</p> <pre><code>totalRecords = query.Count(); </code></pre> <p>The result of this query is :</p> <pre><code>SELECT COUNT([t5].[DocumentID]) FROM ( SELECT [t4].[DocumentID], [t4].[DocumentFrom], [t4].[DocumentTo] FROM ( SELECT [t0].[DocumentID], [t0].[DocumentFrom], [t0].[DocumentTo FROM [dbo].[Document] AS [t0] INNER JOIN [dbo].[User_UserGroup] AS [t1] ON [t0].[DocumentFrom] = [t1].[User_ID] WHERE ([t1].[UserGroupID] = 2) OR ([t1].[UserGroupID] = 3) OR ([t1].[UserGroupID] = 6) UNION SELECT [t2].[DocumentID], [t2].[DocumentFrom], [t2].[DocumentTo] FROM [dbo].[Document] AS [t2] INNER JOIN [dbo].[User_UserGroup] AS [t3] ON [t2].[DocumentTo] = [t3].[User_ID] WHERE ([t3].[UserGroupID] = 2) OR ([t3].[UserGroupID] = 3) OR ([t3].[UserGroupID] = 6) ) AS [t4] ) AS [t5] </code></pre> <p>Can anyone help me to improve the speed of the count query?</p> <p>Thanks in advance!</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