Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improve query generated from entity framework

I have a query linq like this:

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

Linq query generate 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 for not generate subquery?

like image 416
ADIMO Avatar asked Mar 23 '26 20:03

ADIMO


1 Answers

Do you have any evidence that that query is causing performance problems? I imagine the query-optimizer would easily recognize that.

If you're certain after profiling that the query is a performance problem (doubtful) - and only then - you could simply turn the query into a stored procedure, and call that instead.

like image 152
BlueRaja - Danny Pflughoeft Avatar answered Mar 25 '26 08:03

BlueRaja - Danny Pflughoeft



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!