Why operations like where (skip,take) working in memory after select new?

1 posts, 0 answers
  1. Pavel
    Pavel avatar
    3 posts
    Member since:
    Oct 2013

    Posted 07 Oct Link to this post

    Lets say i have following query

        var items = db.Peoples.Select(x => new {x.Id, x.Name})
        .Where(x => x.Name != null).Skip(5).Take(10).ToList();
    and query that executing in database is look like

        select Id, Name from Peoples

    so the question is why where clause, skip, take, working in memory?

    If i use entity framework in same situation, it generates correct query

    SELECT 
        [Project1].[C1] AS [C1], 
        [Project1].[Id] AS [Id], 
        [Project1].[Name] AS [Name]
        FROM ( SELECT 
            [Extent1].[Id] AS [Id], 
            [Extent1].[Name] AS [Name], 
            1 AS [C1]
            FROM [dbo].[People] AS [Extent1]
            WHERE [Extent1].[Name] IS NOT NULL
        )  AS [Project1]
        ORDER BY [Project1].[Name] ASC
        OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY 

Back to Top