I'm new to LinQ and started working with it a couple weeks ago. So maybe i have the wrong understanding how LinQ works. i also tried to use an empty constructor as stated here: Invoke constructor inside a linq query
I changed the constructor of a class. I added the entity energyType
public CSVMeter(int meterID, DateTime datum, int numberOfValues, double total, double total2, double qualityScore, int energyType)
{
this.MeterID = meterID;
this.Datum = datum;
this.NumberOfValues = numberOfValues;
this.total = total;
this.total2 = total2;
this.qualityScore = qualityScore;
this.energyType = energyType;
}
I have the following LinQ query.
public List<CSVMeter> getDisctinctMeters(List<CSVMeter> meterList)
{
newMeterList = newMeterList.GroupBy(x => new { x.MeterID, x.Datum })
.Select(x => new CSVMeter(
x.Key.MeterID,
x.Key.Datum,
x.Sum(s => s.NumberOfValues),
x.Sum(s => s.total),
x.Sum(s => s.total2),
0,
x.energyType))
.ToList();
return meterList;
}
but i get the following error at x.energyType
Error 2 'System.Linq.IGrouping' does not contain a definition for 'energyType' and no extension method 'energyType' accepting a first argument of type 'System.Linq.IGrouping' could be found (are you missing a using directive or an assembly reference?) c:\users\rudi\documents\visual studio 2013\projects\plooscassandra\plooscassandra\handlers\meterbuilder.cs 108 136 PloosCassandra
Why can't i find x.energyType
?