Improving a query generated from an entity structure

I have a linq request as follows:

var query = from c in Context.Customers select c;
var result = query.ToList();

The Linq query generates this tsql code:

exec sp_executesql N'SELECT 
[Project1].[Id] AS [Id], 
[Project1].[Name] AS [Name], 
[Project1].[Email] AS [Email]
FROM ( SELECT 
    [Extent1].[Id] AS [Id],
    [Extent1].[Name] AS [Name], 
    [Extent1].[Email] AS [Email]
    FROM [dbo].[Customers] AS [Extent1] ) AS [Project1]

Is there a way to not generate a subquery?

+3
source share
3 answers

Do you have evidence that this query is causing performance issues? I believe the query optimizer will easily recognize this.

If, after profiling, you are sure that the query is a performance problem (doubtful) - and only then - you can simply include the query in the stored procedure and call it instead.

+5
source

, Linq, SQL, , SQL vs, . SQL Studio , , ...

EDIT: , .

+2

: , .

: Linq , , , , . EF, , EF, , - . SQL-?

+1

All Articles