一、添加扩展
①、配置扩展方法
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"); }
标签:DbType,Args,扩展,expInfo,查询,AbsEquals,大小写,new,sqlsugar From: https://www.cnblogs.com/study10000/p/16911388.html