什么是以下LINQ的扩展方法等效?
var qry = from a in context.A_Collections
from b in context.B_Collections
where a.PK == b.PK
select
new {
A_key = a.PK,
A_Value = a.Value,
B_Key = b.PK,
B_value = b.value
};
Run Code Online (Sandbox Code Playgroud)
我的意思是
(不完全的)
var query = context.A_Collections.
Where(
a => a.PK == context.B_Collections.Select(b => b.PK)).
Select(
x => new {
A_key = a.Pk,
A_Value = a.Value,
B_Key = b.PK,
B_value = b.value
}
);
Run Code Online (Sandbox Code Playgroud)
后续的"from"子句转换为SelectMany调用:
var qry = context.A_Collections
.SelectMany(a => context.B_Collections,
(a, b) => new { a, b })
.Where(x => x.a.PK == x.b.PK)
.Select(x => new { A_key = x.a.PK,
A_value = x.a.Value,
B_key = x.b.PK,
B_value = x.b.Value });
Run Code Online (Sandbox Code Playgroud)
"x"位是由于引入了透明标识符.
请注意,调用Join可能比使用更有效SelectMany(取决于具体情况),但这是您开始使用的查询的更直接的翻译.
| 归档时间: |
|
| 查看次数: |
259 次 |
| 最近记录: |