在我的项目(ASP.net MVC)中,我必须以小写形式返回函数名称(我读入的 CSV 文件)。因为现在我已经对函数进行了分组,并且它返回具有相同名称的函数(有时是小写,有时是大写)。我不知道如何解决这个问题?//HomeControllerpublic List<DescFunctionDataDTO> DescFunctionData(){ Console.WriteLine("DescFunctionData"); var descItemsStamp = db.ChartDatas .GroupBy(x => new { x.Function }); var descItems = descItemsStamp .Select(x => new DescFunctionDataDTO { function = x.Select(b => b.Function).Distinct(), functionavg = Math.Round(x.Average(y => y.Duration), 2), }) .OrderByDescending(x => x.functionavg) .ToList(); return descItems;}//DTOpublic class DescFunctionDataDTO{ public IEnumerable<string> function { get; set; } public double functionavg { get; set; }}//JS-Filefunction showDescDuration() { $.getJSON(`/Home/DescFunctionData`) .then(data => { console.log(data); $('#rankingMax').find("tr:gt(0)").fadeOut().empty(); var i = 1; for (let item of data) { console.log('loop'); $('<tr>').appendTo('#rankingMax') .append($('<td>').html("#"+i)) .append($('<td>').html(item.function)) .append($('<td>').html(item.functionavg + " ms")); i++; } });}
1 回答
ITMISS
TA贡献1871条经验 获得超8个赞
您可以像这样使用预定义函数 string.ToLower() ,
var descItemsStamp = db.ChartDatas
.GroupBy(x => new { x.Function });
var descItems = descItemsStamp
.Select(x => new DescFunctionDataDTO
{
function = x.Select(b => b.Function.ToLower()).Distinct(),
functionavg = Math.Round(x.Average(y => y.Duration), 2),
})
.OrderByDescending(x => x.functionavg)
.ToList();
return descItems;
- 1 回答
- 0 关注
- 78 浏览
添加回答
举报
0/150
提交
取消