首页 > 学院 > 开发设计 > 正文

SQLite中文排序

2019-11-17 02:41:34
字体:
来源:转载
供稿:网友

SQLite中文排序

定义一个类:

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=-1order by ct.typeName COLLATE PinYin
View Code


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表