C# · 12月 19, 2021

SQLite中文排序

定义一个类:

using System.Data.sqlite;namespace DAL{ /// <summary> /// sqlite中文排序 </summary> [sqliteFunction(FuncType = FunctionType.Collation,Name = “PinYin”)] public class sqlitePinYingSort : sqliteFunction { override int Compare(string x,string y) { return .Compare(x,y); } }}View Code

在Global.asax.cs文件的Application_Start方法中添加如下代码:

sqliteFunction.RegisterFunction(typeof(sqlitePinYingSort)); //使sqlite支持中文排序

sql代码:

select ct.* from mas_channel_type ct where ct.pId=-1order by ct.typeName COLLATE PinYinView Code