Linq +嵌套GroupBy

时间:2014-02-25 14:39:42

标签: mysql linq group-by

我们正在使用mySQL和WCF Restful服务,我们希望明智地获取我们的数据库内容PACKAGEID ......如下所述:

    PackageId=2
    {
    StartRange = 1;
    EndRange = 100;
    IsDiscountAndChargeInPer = 1;
    Discount =10;
    ServiceCharge = 20;![enter image description here][1]
    },
    {
    StartRange =101;
    EndRange = 500;
    IsDiscountAndChargeInPer = 1;
    Discount =10;
    ServiceCharge = 20;
    }
    PackageId=3
    {
    StartRange = 1;
    EndRange = 100;
    IsDiscountAndChargeInPer = 1;
    Discount =10;
    ServiceCharge = 20;
    }

我们已经创建了一个Result类来返回来自wcf服务的结果...对于上面的服务,我们将结果类定义如下

[DataContract]
public class PackagePointRangeConfigurationResult : ResultBase
{
    [DataMember]
    public List<PackagePointRangeResult> Result;
}

public class PackagePointRangeResult
{
    public int PackageId { get; set; }

    public List<PointPlanInfo> Result { get; set; }
}

为了获取记录,我们使用以下linq查询:

    var result = (from planinfo in db.mst_pointplan_info
                                  join entityType in db.mst_entity_type
                                  on planinfo.entityId equals entityType.id
                                  where planinfo.entityId == entityId
                                  && planinfo.is_deleted != true
                                  && planinfo.system_id == systemId
                                  && entityType.enity_enum_id == entityId
                                  group planinfo by planinfo.package_id into gplan
                                  select new PackagePointRangeConfigurationResult
                                  {
                                  Result = (from planinfo in gplan
                                            select new PackagePointRangeResult
                                            {
                                                PackageId = planinfo.package_id,
                                                PointPlanInfo = (from pointPlanInfo in gplan
                                                select new PointPlanInfo
                                                {
                                                StartRange = planinfo.start_range,
                                                EndRange = planinfo.end_range,
                                        IsDiscountAndChargeInPer = planinfo.is_discount_and_charge_in_per,
                                                     Discount = planinfo.discount,
                                                     ServiceCharge = planinfo.servicecharge,
                                                     AtonMerchantShare =planinfo.aton_merchant_share,
                                                     CommunityShare = planinfo.community_share
                                                    }).ToList()
                                                }).ToList()
                                  }).FirstOrDefault();

但它给了我以下错误:

  

LINQ to Entities无法识别方法'System.Collections.Generic.List 1[PointPlanInfo] ToList[PointPlanInfo](System.Collections.Generic.IEnumerable 1 [PointPlanInfo])'方法,并且此方法无法转换为商店表达式。

0 个答案:

没有答案