LINQ(lambda语法)为多对多关系选择

彼得·R。

我有具有关系的实体:

包装M--N工厂
包装M--N组件

fe表的内容是:包装(类型1)具有工厂(A,B,C)和组件(1、2、3、4)

我想写LINQ,结果如下:

Type1 A 1
Type1 A 2
Type1 A 3
Type1 A 4
Type1 B 1
Type1 B 2
Type1 B 3
Type1 B 4
Type1 C 1
Type1 C 2
Type1 C 3
Type1 C 4

如何使用具有lambda语法的LINQ获得此信息?

嘴唇

您要从每个源项目中选择许多对象。因此,请使用SelectMany运算符

packagingCollection.SelectMany(p => p.Components.Select(c => new {
            P = p,
            C = c
        })).SelectMany(x => x.P.Factories.Select(f => new {
            P = x.P,
            C = x.C,
            F = f
        })).Select(y => new {
            PackagingName = y.P.Name,
            ComponentName = y.C.Name,
            FactoryName = y.F.Name
        })

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章