比方說,我有這樣一行:不包括導航性能和DB往返
var eggs = db.Nests.Single(b => b.id = 20).Birds.FirstOrDefault().Eggs;
在我的探查器跟蹤,我看到有正在執行多個命令:
SQL:BatchString
SELECT TOP (2)
[Extent1].[id]
...
FROM [dbo].[Nest] AS [Extent1]
WHERE 20 = [Extent1].[id]
SQL:BatchCompleted
RPC:Completed
exec sp_executesql N'SELECT
[Extent1].[Id] AS [Id],
...
FROM [dbo].[Bird] AS [Extent1]
WHERE [Extent1].[NesId] = @EntityKeyValue1',N'@EntityKeyValue1 int',@EntityKeyValue1=20
RPC:Completed
exec sp_executesql N'SELECT
[Extent1].[Id] AS [Id],
...
FROM [dbo].[Egg] AS [Extent1]
WHERE [Extent1].[BirdId] = @EntityKeyValue1',N'@EntityKeyValue1 int',@EntityKeyValue1=13
是否所有那些命令是在同一個請求中執行的,還是每個都有往返?
此外,可我得到確認,這是寫的最有效的方法上面:
var eggs = db.Nests.Include("Birds")
.Single(b => b.id = 20)
.Birds.Include("Eggs")
.FirstOrDefault()
.Eggs;
還是會顯式連接比較好?
Glimpse可能是一個更好的選擇 – 2014-09-22 19:59:15