LinqtoSQlを使用してデータをクエリしています。SQL Server Profilerでorderbyとmonitorを使用してselectクエリを作成すると、selectコマンドが2回実行されます。
- テーブルからフィールドを選択するには
- データを注文します。
データが膨大な場合は時間がかかります。これに対する解決策はありますか?
更新しました:
from dc in dataContext.UserTable join
m in dataContext.MonthLookups on dc.Month equals m.Month into sr
from x in sr.DefaultIfEmpty()
order by dc.UserName, dc.FirstName
select new {dc, sr.MothName};
更新しました:
SELECT
[Project1].[ UserName] AS [UserName],
[Project1].[ FirstName] AS [FirstName],
[Project1].[ MonthName] AS [MonthName],
[Project1].[year] AS [year]
FROM ( SELECT
[Extent1].[UserName] AS [UserName],
[Extent1].[FirstName] AS [FirstName],
[Extent1].[year] AS [year],
[Extent2].[MonthName] AS [MonthName]
FROM [dbo].[DutySavingFin] AS [Extent1]
LEFT OUTER JOIN [dbo].[MonthLookup] AS [Extent2] ON [Extent1].[Month] = [Extent2].[Month]
) AS [Project1]
ORDER BY [Project1].[UserName] ASC, [Project1].[FirstName] ASC
更新しました :
推奨される方法:
SELECT
[Extent1].[UserName] AS [UserName],
[Extent1].[FirstName] AS [FirstName],
[Extent1].[year] AS [year],
[Extent2].[MonthName] AS [MonthName]
FROM [dbo].[DutySavingFin] AS [Extent1]
LEFT OUTER JOIN [dbo].[MonthLookup] AS [Extent2] ON [Extent1].[Month] = [Extent2].[Month]
ORDER BY [Extent1].[UserName] ASC, [Extent1].[FirstName] ASC