将Linq表达式转换为URI时出错:方法'包含'不受支持

时间:2014-06-12 02:00:11

标签: c# linq wcf

我正在尝试使用List过滤数据服务,但是,我收到一些错误消息。有没有办法使用DataServiceQuery过滤List?

DataServiceQuery<Order> ordersQuery = (from x in entities.Orders
                                       .Expand<DataServiceCollection<Shipment>>(a => a.Shipments)
                                       .Expand<DataServiceCollection<OrderItem>>(a => a.OrderItems)
                                       .Expand<OrderStatus>(a => a.OrderStatus)
                                       .Expand<Customer>(a => a.Customer)
                                       .Expand<Store>(a => a.Store)
                                       .Expand<Marketplace>(a => a.Marketplace)
                                       .Expand("Shipments/Carrier")
                                        where  x.OrderStatusID != 4
                                        select x) as DataServiceQuery<Order>;

        if (beginDate != null && endDate != null)
            ordersQuery = ordersQuery.Where(x => x.CreateDate >= beginDate && x.CreateDate <= endDate) as DataServiceQuery<Order>;

        if (statuses != null && statuses.Count() > 0)
        ordersQuery = ordersQuery.Where(a => stores.Contains(a.OrderStatus.Name)) as DataServiceQuery<Order>;

        if (stores != null && stores.Count() > 0)
            ordersQuery = ordersQuery.Where(a => stores.Contains(a.Store.StoreName)) as DataServiceQuery<Order>;

        if (!String.IsNullOrWhiteSpace(orderNumber))
            ordersQuery = ordersQuery.Where(a => a.OrderNumber == orderNumber) as DataServiceQuery<Order>;

该代码以

失败

将Linq表达式转换为URI时出错:不支持“包含”方法。

此代码也失败了:

 if (statuses != null && statuses.Count() > 0)

        {
            var statusFilterList = statuses.Select(title => String.Format("(Name eq {0})", title));
            var statusFilter = String.Join(" or ", statusFilterList);
            ordersQuery.AddQueryOption("$filter", statusFilter).Execute().ToList();

        }

无法添加查询选项'$ filter',因为它会与翻译的Linq表达式中的查询选项冲突。

0 个答案:

没有答案