3

私はほぼ100万のデータを持っていますが、それらすべてをメモリにクエリしてグループ化することは絶対にしたくないので、これを試しましたが、linq2Entityはstring.join()、IEnumerable.toList()などを認識しませんもの

                var capaHrs = (
                from newsPerHr in _dbRawDataContext.CapacityPerHours
                where newsPerHr.StreamDT >= this.BeginDateTime
                                && newsPerHr.StreamDT < this.EndDateTime
                                && newsPerHr.ServerName == this.ServerName
                group newsPerHr by newsPerHr.StreamDT into grp
                let MsgSizeTotal = (from i in grp select i.MsgSize).Sum(x => (int)x)
                let MNumber = (from i in grp select i.MsgNumber).Sum(x => (int)x)
                let Feeds = (from i in grp select i.FeedName).ToArray()
                select new 
                {
                    ServerName = ServerName,
                    FeedName = Feeds,
                    StreamDT = grp.Key,
                    MsgSize = MsgSizeTotal,
                    MsgNumber = MNumber
                }).ToList();

            _capacityData = capaHrs.Select(x => new CapacityPerHour {
                ServerName = x.ServerName,
                FeedName = string.Join(", ",x.FeedName),
                StreamDT = x.StreamDT,
                MsgSize = x.MsgSize,
                MsgNumber = x.MsgNumber
            }).ToList();

それを機能させる方法は?

4

1 に答える 1

2

必要な変更は2つだけです。

  1. ToArrayFeeds宣言のを削除しました
  2. 複数のプロパティを含めることができるように匿名タイプでグループ化されServerNameStreamDT

これを試してみてください:

var capaHrs = (
                from newsPerHr in _dbRawDataContext.CapacityPerHours
                where newsPerHr.StreamDT >= this.BeginDateTime
                                && newsPerHr.StreamDT < this.EndDateTime
                                && newsPerHr.ServerName == this.ServerName
                group newsPerHr by new { newsPerHr.ServerName, newsPerHr.StreamDT } into grp
                let MsgSizeTotal = grp.Sum(x => (int)x.MsgSize)
                let MNumber = grp.Sum(x => (int)x.MsgNumber)
                let Feeds = (from i in grp select i.FeedName)
                select new 
                {
                    ServerName = grp.Key.ServerName,
                    FeedName = Feeds,
                    StreamDT = grp.Key.StreamDT,
                    MsgSize = MsgSizeTotal,
                    MsgNumber = MNumber
                }).ToList();

_capacityData = capaHrs.Select(x => new CapacityPerHour {
                ServerName = x.ServerName,
                FeedName = string.Join(", ",x.FeedName),
                StreamDT = x.StreamDT,
                MsgSize = x.MsgSize,
                MsgNumber = x.MsgNumber
            }).ToList();
于 2012-10-18T14:40:08.233 に答える