Linq'into'关键字混淆
我正在查看同事的Linq查询,如下所示(查询正确执行):
I was looking at a co-workers Linq query, shown below (the query executes correctly):
from ea in EquipmentApplication
join erl in EquipmentRoutingLocation on ea.EquipmentID equals erl.EquipmentID into erlWithNulls
from erlAll in erlWithNulls.DefaultIfEmpty()
join rl in RoutingLocation on erlAll.RoutingLocationID equals rl.RoutingLocationID into rlWithNulls
from rlAll in rlWithNulls.DefaultIfEmpty()
where ea.Equipment.Master_Cell.Area.Unit.UnitID == 1160
select new { ea.Equipment, ea.ApplicationFriendlyName, rlAll }
我对为什么这样做感到困惑.我的理解(可能是错误的)是,"into"关键字结束了当前的作用域/上下文(并且创建的任何变量现在都超出了作用域)并创建了一个新的变量.如果是这样,为什么在查询的最后一部分中'ea'变量仍在作用域内?
I'm confused as to why this works. My understanding (perhaps incorrectly) is that the 'into' keyword ends the current scope/context (and any variables created are now out of scope) and creates a new one. If this is true, why is the 'ea' variable still in scope in the last part of the query?
与select
关键字一起使用时,into
将终止作用域.
与join
关键字一起使用时,into
将添加一个变量,该变量包含联接中的所有匹配项. (这称为组加入)
When used with the select
keyword, into
will end the scope.
When used with the join
keyword, into
will add a variable containing all of the matching items from the join. (This is called a Group Join)