[英]Linq — How to perform Join in ForEach statement?
The Linq Join examples I've seen illustrate hot ti Join when creating an anonymous type. 我看到的Linq Join示例说明了创建匿名类型时的热门ti Join。 How do I do the the Join in a ForEach statement. 如何执行ForEach中的Join语句。
eg 例如
foreach (item i in MyContext.SomeEntity.Include("NavigationProperty1").Include("NavigationProperty2").Join(MyContext.SomeEntity2 on id == id)
{
}
Thanks! 谢谢!
Well, you're trying to mix query syntax with just calling the extension methods directly here - that's not going to work to start with. 好吧,您正在尝试将查询语法与仅在此处直接调用扩展方法混合使用-从头开始是行不通的。
But the result of a join is a sequence of pairs , effectively - pairs which have some property in common. 但是,联接的结果是一系列有效的对 -具有某些共同点的对。 It's not clear where "item" comes from - how do you want each pair from SomeEntity
and SomeEntity2
to be transformed into an item
? 目前尚不清楚“项目”的来源-您如何将SomeEntity
和SomeEntity2
每对转换为item
?
Your call is likely to end up looking something like: 您的通话可能最终看起来像:
...Join(MyContext.SomeEntity2, x => x.id, y => y.id, (x, y) => !!!)
where the !!! 哪里!!! is the projection from a pair of entities to a single useful value. 是从一对实体到单个有用值的投影。
See part 19 of my Edulinq blog series for more information about how the Join
method works. 有关Join
方法如何工作的更多信息,请参见我的Edulinq博客系列的第19部分 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.