Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to filter dynamic linq query on the initial data when there is self-join
    primarykey
    data
    text
    <p>I have a query that I generate by dynamic linq. The problem is when I self-join the initial data set, all other filters are on the latest table. I want it to be on the initial. How can I do that? Here is an example: </p> <pre><code>var result = dataContext.Person; var initialData = result; .... var subQuery = initialData.Where(String.Format(predicateEntityIn, entityPropertyName), subSelection); report = report.Join(subQuery, propertyName, propertyName, "inner"); ... </code></pre> <p>Then I want to filter the initial data on a parameter </p> <pre><code>report = report.Where(String.Format("{0} = {1}", "PersonId", paramValue)); </code></pre> <p>If I don't have the inner join then the query is correctly filtered, but with the inner join it does the filtering on the latest query of the initial type and also the select is on the latest table. The query that is generated is something like that:</p> <pre><code>SELECT DISTINCT [t2].[Field1], [t2].[PersonId], [t2].[Field2] FROM [dbo].[PersonDetails] AS [t0] INNER JOIN [dbo].[Person] AS [t1] ON [t1].[PersonId] = [t0].[PersonId] INNER JOIN [dbo].[PersonDetails] AS [t2] ON [t0].[PersonId] = [t2].[PersonId] WHERE ([t2].[YearOfBirth] = 2012) </code></pre> <p>But I want it to be: </p> <pre><code>SELECT DISTINCT [t0].[Field1], [t0].[PersonId], [t0].[Field2] FROM [dbo].[PersonDetails] AS [t0] INNER JOIN [dbo].[Person] AS [t1] ON [t1].[PersonId] = [t0].[PersonId] INNER JOIN [dbo].[PersonDetails] AS [t2] ON [t0].[PersonId] = [t2].[PersonId] WHERE ([t0].[YearOfBirth] = 2012) </code></pre>
    singulars
    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.
 

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