Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad SQL #38

Closed
genusP opened this issue Oct 2, 2013 · 1 comment
Closed

Bad SQL #38

genusP opened this issue Oct 2, 2013 · 1 comment

Comments

@genusP
Copy link
Contributor

genusP commented Oct 2, 2013

For LINQ query:

from a in Assignments
                     where a.AssignmentsRelayAssignment.Relay_Id == 2
                           && a.AssignmentsRelayAssignment.Type == "Organizations"
                     select new Models.AssignmentGridItem
                     {
                         Id = a.Id,
                         DeliveryDate = a.DeliveryDate,
                         UndeliveryDate = a.UndeliveryDate,
                         WorksCount = a.WorksToAssignments.Count(),
                     };

generate SQL:

SELECT
    [a].[Id],
    [a].[DeliveryDate],
    [a].[UndeliveryDate],
    (
        SELECT
            Count(*)
        FROM
            [dbo].[Works] [c]
        WHERE
            [a].[Id] = [c].[Assignment_Id]
    ) as [c1]
FROM
    [dbo].[Assignments] [a]
        INNER JOIN [dbo].[AssignmentsRelay] [t1] ON [a].[Id] = [t1].[Id]
        INNER JOIN [dbo].[Works] [t2] ON [a].[Id] = [t2].[Assignment_Id]
WHERE
    [t1].[Relay_Id] = 2 AND [t1].[Type] = 'Organizations'

Join to Works table not need

@genusP
Copy link
Contributor Author

genusP commented Oct 2, 2013

PS. Please check issue #24

igor-tkachev added a commit that referenced this issue Apr 2, 2014
MaceWindu pushed a commit that referenced this issue Oct 1, 2021
I've encountered a case when SingleOrDefault() (at line #38) throws `InvalidOperationException` due to finding more than one assembly item in the collection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant