【发布时间】:2015-02-19 06:22:47
【问题描述】:
所以标题可能没有意义......
我有一个产品列表
"Ind Apples", "Ind Bananas", "Ind Carrots", "Ind Dates", "Ind Eggplants", "Bulk Apples", "Bulk Bananas", "Bulk Carrots", "Bulk Dates", "Potatoes", "Oranges", "Melons"
我的 linq 查询如下:
var query = db.products
.OrderBy(c => c.ProductName.StartsWith("Ind"))
.ThenBy(c => c.ProductName.StartsWith("Bulk"));
我希望我的列表首先显示所有以“Ind”开头的项目,然后是以“Bulk”开头的项目,然后是其他所有项目......
我的列表中的内容如下:
"Ind Bananas"
"Ind Eggplants"
"Ind Carrots"
"Ind Apples"
"Bulk Apples"
"Bulk Dates"
"Bulk Carrots"
"Bulk Bananas"
"Oranges"
"Melons"
"Potatoes"
所以它是按我的规范排序的......但在每个分组“Ind”,“Bulk”中它不是......有没有办法(除了浏览列表并手动指定我想要每个项目的位置) 在 linq 中实现这一点????
【问题讨论】: