1

私はうまく動作するこのLinqクエリを持っています

var test = (from c in context.ConsumptionSet
            join pi in context.PropertiesInstanceSet on c.PropertiesInstanceID equals pi.PropertiesInstanceID
            join ep in context.EquipmentPropertiesSet on pi.EquipmentPropertiesID equals ep.EquipmentPropertiesID
            where (ep.EquipmentID == equipmentId && pi.ProprietesName == ProprietesName.Energy && c.Date <= DateTime.Today && c.Date >= EntityFunctions.AddDays(DateTime.Today, -7))
            group c by c.Date.Day into grp
            select new
            {
               test = grp.Key,
               value = (from c2 in grp select c2.Value).Max()

            }).ToList();

しかし、これらの結果をプロパティでグループ化したいのですが、次のように置き換えるとこのエラーが発生するため、Linq では許可さDayOfWeekれていないようです。 group c by c.Date.Daygroup c by c.Date.DayOfWeekThe specified type member 'DayOfWeek' is not supported in LINQ to Entities

この問題の回避策はありますか?

4

1 に答える 1

6

使用SqlFunctions.DatePart:

var test = (from c in context.ConsumptionSet
            join pi in context.PropertiesInstanceSet on c.PropertiesInstanceID equals pi.PropertiesInstanceID
            join ep in context.EquipmentPropertiesSet on pi.EquipmentPropertiesID equals ep.EquipmentPropertiesID
            where (ep.EquipmentID == equipmentId && pi.ProprietesName == ProprietesName.Energy && c.Date <= DateTime.Today && c.Date >= EntityFunctions.AddDays(DateTime.Today, -7))
            group c by SqlFunctions.DatePart("weekday", c.Date) into grp
            select new
            {
               test = grp.Key,
               value = (from c2 in grp select c2.Value).Max()

            }).ToList();
于 2013-04-09T16:28:30.870 に答える