I want to know which operators we have like group by that linq to sql translates them to multiple queries and what can we do to prevent it , I think this is a performance issue.
for example I have this simple linq query :
var productList = products.GroupBy(s => new { s.LastSale }).ToList();
I have 3 groups in my data in Product table in database therefore I see 3 execution of query in sql profiler :
1.exec sp_executesql N'SELECT [t0].[ID], [t0].[Description], [t0].[Discontinued], [t0].[LastSale]
FROM [dbo].[Product] AS [t0]
WHERE @x1 = [t0].[LastSale]',N'@x1 date',@x1='2015-02-07'
2.exec sp_executesql N'SELECT [t0].[ID], [t0].[Description], [t0].[Discontinued], [t0].[LastSale]
FROM [dbo].[Product] AS [t0]
WHERE @x1 = [t0].[LastSale]',N'@x1 date',@x1='2015-04-08'
3.exec sp_executesql N'SELECT [t0].[ID], [t0].[Description], [t0].[Discontinued], [t0].[LastSale]
FROM [dbo].[Product] AS [t0]
WHERE @x1 = [t0].[LastSale]',N'@x1 date',@x1='2015-04-09'
Thank you