我希望能够对子 linq 查询进行分组,但 LinqPad 在这一行给出错误:
ratetocharge =rtc.rate.Sum
错误是:无法将方法组分配给匿名类型属性。
任何人都可以建议我应该在该行中输入什么,以便给我费率表中的费率总和吗?
谢谢,
标记
var mtgRooms = RoomUnit
.Where(r => r.building_id==1)
.GroupBy(p => p.Type)
.Select(g => new
{
TypeName = g.Key.type_name,
TypeID = g.Key.type_id,
TypeCount = g.Count(),
rates = rates
.Select ( rtc =>
new
{
occ = rtc.occ,
ratetocharge =rtc.rate.Sum // this is the line which errors
}
)
.GroupBy(pe => pe.occ)
}
);
mtgRooms.Dump();
编辑:添加更多细节
表:
桌房单位
type_id (key - int)
type_name (string - eg. large room, small room, medium room)
building_id (int - denotes a number of buildings this room could be within)
费率
rate_id
type_id (foreign key to RoomUnit)
occ (type of rate - ie. Desk, FullRoom)
这个想法是我想提供一个看起来像这样的模型:
Type of Room
Number of Types of Room available
Type of Occ/Desks available
Sum of Rate (rate to charge) for each type of desk
目前显示的是:
LargeRoom, Type 3049, Type Count 18 (or whatever is available)
occ FullRoom, ratetocharge 250, numOfOcc 1
occ FullRoom, ratetocharge 250, numOfOcc 1
occ FullRoom, ratetocharge 250, numOfOcc 1
occ Single Desk, ratetocharge 45, numOfOcc 1
occ Single Desk, ratetocharge 45, numOfOcc 1
SmallRoom, Type 3093, Type Count 4 (or whatever is available)
occ FullRoom, ratetocharge 150, numOfOcc 1
occ FullRoom, ratetocharge 150, numOfOcc 1
occ Single Desk, ratetocharge 45, numOfOcc 1
occ Single Desk, ratetocharge 45, numOfOcc 1
occ Single Desk, ratetocharge 45, numOfOcc 1
而我希望模型在子表中按 Occ 对 rateToCharge 求和,例如:
LargeRoom, Type 3049, Type Count 18 (or whatever is available)
occ FullRoom, ratetocharge 750, numOfOcc 3
occ Single Desk, ratetocharge 90, numOfOcc 2
SmallRoom, Type 3093, Type Count 4 (or whatever is available)
occ FullRoom, ratetocharge 300, numOfOcc 2
occ Single Desk, ratetocharge 135, numOfOcc 3