sqlsugar 扩展区分大小写查询

一、添加扩展

       ①、配置扩展方法

   var context= new SqlSugarScope(new ConnectionConfig()
            {
                DbType = DbType.MySqlConnector,
                InitKeyType = InitKeyType.Attribute,
                IsAutoCloseConnection = true,
                ConnectionString = RepositoryConfig.ConnectionString,
                ConfigureExternalServices = new ConfigureExternalServices()
                {
                    SqlFuncServices= new List<SqlFuncExternal>
                    {
                        new SqlFuncExternal()
                        {
                            UniqueMethodName="AbsEquals",
                            MethodValue = (expInfo, dbType, context) =>
                            {
                                if(dbType==DbType.MySql)
                                    return $" binary {expInfo.Args[0].MemberName}='{expInfo.Args[1].MemberValue}' "return $" {expInfo.Args[0].MemberName}='{expInfo.Args[1].MemberValue}' ";
                            }
                        }
                    }
                }
            });

       ②、使用扩展方法

var user = context.Queryable<User>(p => SqlFuncEx.AbsEquals(p.Account, "Apricot")).FirstAsync();

       ③、扩展类

public static class SqlFuncEx
{
    public static bool AbsEquals(string first, string second)
        => throw new NotSupportedException("Can only be used in expressions");
}

 

posted @ 2022-11-21 14:51  1764564459  阅读(626)  评论(0)    收藏  举报