Я предполагаю, что ваши db.Sales
данные выглядят так:
List<Sales> mySales = new List<Sales>()
{
new Sales
{
Id = 1,
PointName = "wwwfhfghfgh",
Picture = "~/Images/PointPicuters/637321819464806362a.png",
FullType = "Petrol",
SaleQuantity = 100.00M
},
new Sales
{
Id = 2,
PointName = "wwwfhfghfgh",
Picture = "~/Images/PointPicuters/637321819464806362a.png",
FullType = "Petrol",
SaleQuantity = 200.00M
},
new Sales
{
Id = 3,
PointName = "wwwfhfghfgh",
Picture = "~/Images/PointPicuters/637321819464806362a.png",
FullType = "GasLocal",
SaleQuantity = 300.00M
},
new Sales
{
Id = 4,
PointName = "wwwfhfghfgh",
Picture = "~/Images/PointPicuters/637321819464806362a.png",
FullType = "GasLocal",
SaleQuantity = 400.00M
},
new Sales
{
Id = 5,
PointName = "wwwfhfghfgh",
Picture = "~/Images/PointPicuters/637321819464806362a.png",
FullType = "Petrol_95",
SaleQuantity = 500.00M
},
new Sales
{
Id = 6,
PointName = "wwwfhfghfgh",
Picture = "~/Images/PointPicuters/637321819464806362a.png",
FullType = "Petrol_95",
SaleQuantity = 600.00M
},
new Sales
{
Id = 7,
PointName = "www",
Picture = "~/Images/PointPicuters/63732163747332.jpg",
FullType = "MyNewType",
SaleQuantity = 10000.00M
},
new Sales
{
Id = 8,
PointName = "www",
Picture = "~/Images/PointPicuters/63732163747332.jpg",
FullType = "MyNewType",
SaleQuantity = 20000.00M
}
};
После 2 групп по операциям
var queryGroupByFullType = from s in mySales
group s by s.FullType into newGroup1
select new
{
MeterReading = newGroup1.Sum(x => x.SaleQuantity),
PointName = newGroup1.First().PointName,
Picture = newGroup1.First().Picture,
FullType = newGroup1.Key
};
var queryGroypByPointName = from s in queryGroupByFullType
group s by s.PointName into newGroup1
select new
{
Point = newGroup1.Key,
Picture = newGroup1.First().Picture,
MyList = newGroup1.Select(x => new
{
x.MeterReading,
x.FullType
})
};
json:
[
{
"point":"wwwfhfghfgh",
"picture":"~/Images/PointPicuters/637321819464806362a.png",
"myList":[
{
"meterReading":300.00,
"fullType":"Petrol"
},
{
"meterReading":700.00,
"fullType":"GasLocal"
},
{
"meterReading":1100.00,
"fullType":"Petrol_95"
}
]
},
{
"point":"www",
"picture":"~/Images/PointPicuters/63732163747332.jpg",
"myList":[
{
"meterReading":30000.00,
"fullType":"MyNewType"
}
]
}
]