您的位置:首页 > 博客中心 > 数据库 >

SQLite中文排序

时间:2022-03-14 04:11

定义一个类:

技术分享技术分享
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);
        }
    }
}
View Code

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

SQLiteFunction.RegisterFunction(typeof(SQLitePinYingSort)); //使SQLite支持中文排序

SQL代码:

技术分享技术分享
select ct.* 
from mas_channel_type ct 
where ct.pId=-1
order by ct.typeName COLLATE PinYin
View Code

 

热门排行

今日推荐

热门手游