LINQ到实体无法识别方法Generic.List(int)以Generic.IEnumerable(int)方法 [英] LINQ to Entities does not recognize the method Generic.List(int) to Generic.IEnumerable(int) method

查看:217
本文介绍了LINQ到实体无法识别方法Generic.List(int)以Generic.IEnumerable(int)方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该数据库包含的订单。
订单可以被包含在一组订单内。
。对于每个组订单可能包含1到不少订单。

The database contains Orders. Orders can be contained within a group of Orders. For every group of Orders it could contain 1 to many Orders.

不过,订单可能分配GroupOrderId一个NULL值,以前的订单没有分组概念。只有新订单执行被添加到一个组的概念。

However, Orders could have a NULL value assigned GroupOrderId as previous Orders did not have the grouping concept. Only new Orders enforce the concept of being added to a group.

阶级结构,以便每个订单执行操作是

The class structure to be populated in order to perform actions on each Order is

public class OrdersGroup
{
    public int? GroupOrderId { get; set; }
    public List<int> OrderIds { get; set; }
}



LINQ的声明

The linq statement

var workPacketOrdersList = (from o in db.Orders
                                    where
                                        o.GroupOrderId >= groupOrderIdMin && o.GroupOrderId <= groupOrderIdMax &&
                                        o.IsDeleted == false
                                    orderby o.WorkPacketId ascending
                                    group o by o.WorkPacketId
                                    into grp
                                    select new OrdersGroup
                                               {
                                                   GroupOrderId = grp.Key,
                                                   OrderIds = grp.Select(g => g.OrderId).ToList()
                                               }).ToList();



全部例外

Full exception

LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[System.Int32] ToList[Int32](System.Collections.Generic.IEnumerable`1[System.Int32])' method, and this method cannot be translated into a store expression.



我看到LINQ查询的返回类型为列表< OrdersGroup> ;

如果最终.ToList()从查询中省略比返回类型变成的IQueryable< OrdersGroup方式>

If the final .ToList() is omitted from the query than the return type becomes an IQueryable<OrdersGroup>

不管接下来的结果却是一个例外,这种方法不能被翻译成店表达式执行什么动作。

No matter what action is performed next the result is an exception that this method cannot be translated into a store expression.

我试图删除的特定选择新OrdersGroup 成一个更通用选择新的,然后这个结果执行动作才发现,同店表现的异常。

I have tried to remove the specific select new OrdersGroup into a more generic select new and then perform actions on this result only to find the same store expression exception.

有人可以给一些洞察到其中,这LINQ是不正确的?

Can someone give some insight into where this linq is incorrect?

推荐答案

这是一个失败的部分 - grp.Select(G => g.OrderId).ToList( ) - 你不能有一个.ToList()选择子句。除去这一点,你应该罚款。

this is the part that's failing - grp.Select(g => g.OrderId).ToList() - you can't have a .ToList() in the select clause. remove that and you should be fine.

这篇关于LINQ到实体无法识别方法Generic.List(int)以Generic.IEnumerable(int)方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆