请考虑以下查询:
from r in ent.MyTable
group r by new { r.EmployeeName, r.EmployeeID } into g
let c = " (" + SqlFunctions.StringConvert((decimal?)g.Count()) + " )"
select new
{
EmployeeName = g.Key.EmployeeName + c ,
EmployeeID = g.Key.EmployeeID
});
它运作良好。当我想改用此查询时,出现错误:
from r in ent.MyTable
group r by new { r.EmployeeName, r.EmployeeID } into g
select new
{
EmployeeName = g.Key.EmployeeName + " (" + g.Count() + ")",
EmployeeID = g.Key.EmployeeID
});
错误:
我怎样才能做到这一点?
最佳答案
为什么不对输出进行双重转换?
from r in ent.MyTable
group r by new { r.EmployeeName, r.EmployeeID } into g
select new
{
EmployeeName = g.Key.EmployeeName,
Count = g.Count(),
EmployeeID = g.Key.EmployeeID
}
into tmp
select new
{
EmployeeName = tmp.EmployeeName + "(" + Count + ")",
EmployeeID = tmp.EmployeeID
}