8,497
社区成员
发帖
与我相关
我的任务
分享
contractNO(字段)
AX-001
AX-002
AX-003
BYT-001
BYT-002
CD-01
CD-02
var query = from c in db.ConditionsContracts
where c.contractNO.StartsWith(classNO)
orderby c.contractNO
select c;
string[] testAry = new string[] { "AX-001", "AX-002", "AX-003", "BYT-001", "BYT-002", "CD-01", "CD-02" };
var result = from key in testAry
group key by key.Split('-')[0] into g
select g.Max();
foreach (var item in result)
{
Console.WriteLine(item);
}
// 输出
// AX-003
// BYT-002
// CD-02
List<string> li = new List<string>();
li.AddRange(new[] { "AX-001", "AX-002", "AX-003", "BYT-001", "BYT-002", "CD-01", "CD-02" });
var q = from c in li
group c by c.Split('-')[0] into d
select new { classno = d.Key, maxno = d.Max() };
var query = (from c in db.ConditionsContracts
where c.contractNO.StartsWith(classNO)
orderby int.Parse(Regex.Match(c.contractNO,@"(?<=-)\d+").Value) descending
select c).FirstOrDefault();
var query = (from c in db.ConditionsContracts
where c.contractNO.StartsWith(classNO)
orderby int.Parse(c.contractNO.SubString(classNO.Length + 1)) descending
select c)
.First();