Linq to object Group Join Overflow exception

时间:2017-05-14 04:24:06

标签: c# performance linq

我有4个对象

public class DataInfo
{
    public int BannerId { get; set; }
    public int AdsType { get; set; }

    public int SiteId { get; set; }
    public int MngSiteId { get; set; }
    public string SiteName { get; set; }

    public int PositionId { get; set; }
    public int MngPositionId { get; set; }
    public string PositionName { get; set; }

    public int MngCategoryId { get; set; }
    public int CategoryId { get; set; }
    public string CategoryName { get; set; }

    public DateTime LogDate { get; set; }

    public double Impression { get; set; }
    public double Click { get; set; }
    public double CTR { get; set; }
}

public class ZoneInfo
{
    public int MngSiteId { get; set; }
    public int SiteId { get; set; }
    public string SiteName { get; set; }

    public int MngPositionId { get; set; }
    public int PositionId { get; set; }
    public string PositionName { get; set; }

    public int MngCategoryId { get; set; }
    public int CategoryId { get; set; }
    public string CategoryName { get; set; }

    public int AdsSale { get; set; }

}

public class LogTotalInfo
{
    public int TotalId { get; set; }
    public DateTime LogDate { get; set; }
    public double Click { get; set; }
    public double Action { get; set; }
    public double Impression { get; set; }
    public int AdsType { get; set; }
    public int SiteId { get; set; }
    public int PositionId { get; set; }
    public int CategoryId { get; set; }
    public int BannerId { get; set; }
    public double Visitor { get; set; }
    public double UniqueClick { get; set; }
}

public class ProductInfo
{
    public int ProductId { get; set; }
    public int BannerId { get; set; }
    public int LabelId { get; set; }
    public int ProductType { get; set; }
    public string BannerName { get; set; }
    public string LabelName { get; set; }
}

我加入linq

List<DataInfo> di = (from t in tTotal // LogTotalInfo
                    join p in tProduct // ProductInfo
                    on t.BannerId equals p.BannerId
                    join z in tZone // ZoneInfo
                    on new { t.SiteId, t.CategoryId, t.PositionId } equals new { z.SiteId, z.CategoryId, z.PositionId }
                    group new { t, p, z } by new { z.MngSiteId, z.MngCategoryId, z.MngPositionId, z.PositionName, z.SiteName, z.CategoryName, t.AdsType, t.LogDate } into cg2
                    select new DataInfo
                    {
                        LogDate = cg2.Key.LogDate,
                        MngSiteId = cg2.Key.MngSiteId,
                        MngCategoryId = cg2.Key.MngCategoryId,
                        MngPositionId = cg2.Key.MngPositionId,
                        PositionName = cg2.Key.PositionName,
                        SiteName = cg2.Key.SiteName,
                        CategoryName = cg2.Key.CategoryName,
                        AdsType = cg2.Key.AdsType,
                        Impression = cg2.Sum(x => x.t.Impression),
                        Click = cg2.Sum(x => x.t.Click)
                    }).ToList();

它会在group new { t, p, z }处抛出溢出异常。 tZone ~10k记录,tTotal ~2m记录和tProduct ~65k记录。  如何加入而不是例外或任何其他方式来获得相同的结果

0 个答案:

没有答案