【发布时间】:2020-01-29 09:11:13
【问题描述】:
我在数据库中有以下数据。
01-001-A-02
01-001-A-01
01-001-B-01
01-002-A-01
01-003-A-01
从上面,我想要如下排序的数据:
01-001-A-01
01-001-A-02
01-001-B-01
...
我的查询如下
var l = _context.Locs.OrderBy(o => o.loc).Take(3);
//result of the Query
01-001-A-01
01-002-A-01
01-003-A-01
这是我的表结构
public class Location
{
[Key]
public int id { get; set; }
public string loc { get; set; }
public bool isEmpty { get; set; }
}
我正在使用Asp.Net Core 2.2, Code-First 方法。这不是计算列。
用'-'分割后需要从右到左排序
我在LINQ 查询中遗漏了什么?
【问题讨论】:
-
您能否更新您的问题以更清楚地了解数据结构(列和类型)以及
Locs和loc是什么?
标签: c# linq asp.net-core-2.2