from component in Materials.OfType<Container>().Where(m => m.Active) join segmentFinancerating in segmentFinanceratingView on component.Id equals segmentFinancerating.MaterialId into segmentFinanceratingGroup from segmentFinanceratingWithDefault in segmentFinanceratingGroup.DefaultIfEmpty() select new { id = component.Id,name = component.Name,subType = component.SubType,size = component.Size,MaterialIds = component.Materials.Select(x => x.Id),BrandNames = component.Brands.Select(x => x.Name),Segmentratings = segmentFinanceratingWithDefault }
我有上面的LINQ to Entities查询,它有一个LEFT JOIN来获取给定组件的1个或多个段的评级值.
segmentFinancerating实体具有{MaterialId,SegmentId,rating,LowRated}属性
目前,结果未分组到相关组件,即Segmentratings属性不是segmentFinancerating对象的单个集合,而是我有多个数据行,每个数据行中包含1个segmentFinancerating对象.
我已经看到了一些使用x组进入z的例子但是我无法使它工作,可能是由于我需要的组件上的一些集合,我不确定.
如果这样做,任何帮助将不胜感激,谢谢.
解决方法
列表中的GroupBy不适合您?
var list = (from component in Materials.OfType<Container>().Where(m => m.Active) join segmentFinancerating in segmentFinanceratingView on component.Id equals segmentFinancerating.MaterialId into segmentFinanceratingGroup from segmentFinanceratingWithDefault in segmentFinanceratingGroup.DefaultIfEmpty() select new { id = component.Id,Segmentratings = segmentFinanceratingWithDefault }).ToList().GroupBy(s=> s.Segmentratings);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。