定义一个类:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
using System.Data.SQLite; namespace DAL { /// <summary> /// SQLite中文排序 /// </summary> [SQLiteFunction(FuncType = FunctionType.Collation, Name = "PinYin")] public class SQLitePinYingSort : SQLiteFunction { public override int Compare(string x, string y) { return string.Compare(x, y); } } }
在Global.asax.cs文件的Application_Start方法中添加如下代码:
SQLiteFunction.RegisterFunction(typeof(SQLitePinYingSort)); //使SQLite支持中文排序
SQL代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
select ct.* from mas_channel_type ct where ct.pId=-1 order by ct.typeName COLLATE PinYin