在LINQ to Entities上拆分组 - 复合查询

时间:2015-04-22 10:05:38

标签: c# linq entity-framework linq-to-entities entity-framework-6

我们说我有这样的事情:

... //Group By A
into anotherGroupByRangeVariable
...//Group By B
           Operation =  from item in anotherGroupByRangeVariable
                        group featureTitleGroupItem by
                        someKey into operationGrouping

                        select new Operation()
                        {
                            myProperty = operationGrouping.Key,
                            ...Other Attributes
                        });

为什么我无法提取第二个group by并将其用于以下方法:

private static IQueryable<Operation> GroupByFeatureTitle(IGrouping<string, GroupByAItem> featureTitleGrouping)
        {
            return from item in anotherGroupByRangeVariable
                        group featureTitleGroupItem by
                        someKey into operationGrouping

                        select new Operation()
                        {
                            myProperty = operationGrouping.Key,
                            ...Other Attributes
                        }).AsQueryable();
        }

拨打电话:

 ... //Group By A
    into anotherGroupByRangeVariable
    ...//Group By B
               Operation =  GroupByFeatureTitle(anotherGroupByRangeVariable)

当我尝试执行它时,我收到错误:

LINQ to Entities does not recognize the method 'System.Linq.IQueryable`1[Operation] GroupByFeatureTitle(System.Linq.IGrouping`2[NotificationChannelDao+ScopeChannelType])' method, and this method cannot be translated into a store expression.

在LINQ to Entities中使用多个内部组进行复合查询以使代码更具可读性的最佳方法是什么?

0 个答案:

没有答案