diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index a76334431..7ffe94cfa 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -549,7 +549,6 @@ static void Main(string[] args) .UseNameConvert(NameConvertType.ToLower) //.UseMappingPriority(MappingPriorityType.Attribute, MappingPriorityType.FluentApi, MappingPriorityType.Aop) .UseAdoConnectionPool(true) - .UseConnectionFactory(DataType.Xugu, () => null) //.UseConnectionString(FreeSql.DataType.Sqlite, "data source=123.db") //.UseConnectionString(DataType.Sqlite, "data source=db1.db;attachs=db2.db") @@ -560,7 +559,7 @@ static void Main(string[] args) //.UseConnectionString(FreeSql.DataType.Firebird, @"database=localhost:D:\fbdata\EXAMPLES.fdb;user=sysdba;password=123456;max pool size=5") //.UseQuoteSqlName(false) - //.UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;min pool size=1;Max pool size=3;AllowLoadLocalInfile=true") + .UseConnectionString(FreeSql.DataType.MySql, "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=cccddd;Charset=utf8;SslMode=none;min pool size=1;Max pool size=3;AllowLoadLocalInfile=true") //.UseConnectionString(FreeSql.DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true") //.UseAdoConnectionPool(false) @@ -599,13 +598,21 @@ static void Main(string[] args) .UseGenerateCommandParameterWithLambda(true) .Build(); BaseEntity.Initialization(fsql, () => _asyncUow.Value); - #endregion + #endregion + + var v1 = 123123123; + var mysql0111 = fsql.Select().Where(a => a.Nickname.Contains(v1.ToString())).ToSql(); + var mysql0112 = fsql.Select().Where(a => a.Nickname.Contains(123123123.ToString())).ToSql(); + var v2 = "123123123"; + var mysql0113 = fsql.Select().Where(a => a.Nickname.Contains(v2)).ToSql(); + var mysql0114 = fsql.Select().Where(a => a.Nickname.Contains(v2.ToString())).ToSql(); + var mysql0115 = fsql.Select().Where(a => a.Nickname.Contains("123123123")).ToSql(); //fsql.Select().Where(a => a.createtime > DateTime.Now && a.createtime < DateTime.Now.AddMonths(1)).ToList(); - //var table = fsql.CodeFirst.GetTableByEntity(typeof(AsTableLog)); - //table.SetAsTable(new ModAsTableImpl(fsql), table.ColumnsByCs[nameof(AsTableLog.click)]); + //var table = fsql.CodeFirst.GetTableByEntity(typeof(AsTableLog)); + //table.SetAsTable(new ModAsTableImpl(fsql), table.ColumnsByCs[nameof(AsTableLog.click)]); - fsql.CodeFirst.GetTableByEntity(typeof(AsTableLog)).AsTableImpl + fsql.CodeFirst.GetTableByEntity(typeof(AsTableLog)).AsTableImpl .SetTableName(0, "AsTableLog1") .SetTableName(1, "AsTableLog2"); diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml index 537315e21..26522f106 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.xml +++ b/FreeSql.DbContext/FreeSql.DbContext.xml @@ -800,5 +800,14 @@ + + + 批量注入 Repository,可以参考代码自行调整 + + + + + + diff --git a/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs b/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs index d4a7ea742..5f72b6d14 100644 --- a/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs +++ b/Providers/FreeSql.Provider.ClickHouse/ClickHouseExpression.cs @@ -99,6 +99,8 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as String)" : null; } return null; diff --git a/Providers/FreeSql.Provider.Custom/CustomExpression.cs b/Providers/FreeSql.Provider.Custom/CustomExpression.cs index 82e294066..8e5cc1ca0 100644 --- a/Providers/FreeSql.Provider.Custom/CustomExpression.cs +++ b/Providers/FreeSql.Provider.Custom/CustomExpression.cs @@ -99,8 +99,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? _utils.Adapter.LambdaConvert_ToString(callExp.Object.Type, getExp(callExp.Object)) : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? _utils.Adapter.LambdaConvert_ToString(callExp.Object.Type, getExp(callExp.Object)) : null; } return null; } diff --git a/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs b/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs index 9a5670337..f02bac5c8 100644 --- a/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs +++ b/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlExpression.cs @@ -95,8 +95,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as char)" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as char)" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs b/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs index ade84d945..0bef32718 100644 --- a/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs +++ b/Providers/FreeSql.Provider.Custom/Oracle/CustomOracleExpression.cs @@ -99,8 +99,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs b/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs index e1c7f9388..df242034e 100644 --- a/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs +++ b/Providers/FreeSql.Provider.Custom/PostgreSQL/CustomPostgreSQLExpression.cs @@ -98,8 +98,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs b/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs index b48de418c..37b7e4bea 100644 --- a/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs +++ b/Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerExpression.cs @@ -103,8 +103,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? (gentype2 == typeof(Guid) ? + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? (gentype2 == typeof(Guid) ? $"cast({getExp(callExp.Object)} as varchar(36))" : $"cast({getExp(callExp.Object)} as nvarchar{(gentype2.IsNumberType() || gentype2.IsEnum ? "(100)" : "(max)")})") : null; } diff --git a/Providers/FreeSql.Provider.Dameng/DamengExpression.cs b/Providers/FreeSql.Provider.Dameng/DamengExpression.cs index 1a91444b5..5a79dd501 100644 --- a/Providers/FreeSql.Provider.Dameng/DamengExpression.cs +++ b/Providers/FreeSql.Provider.Dameng/DamengExpression.cs @@ -99,8 +99,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs b/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs index f45a3d8ff..a652284e0 100644 --- a/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs +++ b/Providers/FreeSql.Provider.Firebird/FirebirdExpression.cs @@ -96,8 +96,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as blob sub_type 1)" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as blob sub_type 1)" : null; } return null; } diff --git a/Providers/FreeSql.Provider.GBase/GBaseExpression.cs b/Providers/FreeSql.Provider.GBase/GBaseExpression.cs index 14f1b6828..d848dd3c4 100644 --- a/Providers/FreeSql.Provider.GBase/GBaseExpression.cs +++ b/Providers/FreeSql.Provider.GBase/GBaseExpression.cs @@ -96,8 +96,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as varchar(8000))" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as varchar(8000))" : null; } return null; } diff --git a/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs b/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs index 272a328eb..f105376ce 100644 --- a/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs +++ b/Providers/FreeSql.Provider.KingbaseES/KingbaseESExpression.cs @@ -98,8 +98,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; } return null; } diff --git a/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs b/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs index fc822109e..fb7a0dae6 100644 --- a/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs +++ b/Providers/FreeSql.Provider.MsAccess/MsAccessExpression.cs @@ -69,8 +69,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? MsAccessUtils.GetCastSql(getExp(callExp.Object), typeof(string)) : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? MsAccessUtils.GetCastSql(getExp(callExp.Object), typeof(string)) : null; } return null; } diff --git a/Providers/FreeSql.Provider.MySql/MySqlExpression.cs b/Providers/FreeSql.Provider.MySql/MySqlExpression.cs index 722abaacb..c5a034411 100644 --- a/Providers/FreeSql.Provider.MySql/MySqlExpression.cs +++ b/Providers/FreeSql.Provider.MySql/MySqlExpression.cs @@ -97,8 +97,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as char)" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as char)" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs index f035f8dd3..130457224 100644 --- a/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/Dameng/OdbcDamengExpression.cs @@ -99,8 +99,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Odbc/Default/OdbcExpression.cs b/Providers/FreeSql.Provider.Odbc/Default/OdbcExpression.cs index bc3cde86a..24d22582e 100644 --- a/Providers/FreeSql.Provider.Odbc/Default/OdbcExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/Default/OdbcExpression.cs @@ -99,8 +99,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? _utils.Adapter.LambdaConvert_ToString(callExp.Object.Type, getExp(callExp.Object)) : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? _utils.Adapter.LambdaConvert_ToString(callExp.Object.Type, getExp(callExp.Object)) : null; } return null; } diff --git a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs index 8a91d8ae9..91a541fe1 100644 --- a/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/KingbaseES/OdbcKingbaseESExpression.cs @@ -98,8 +98,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs index e65530233..dc0a7b01b 100644 --- a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlExpression.cs @@ -95,8 +95,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as char)" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as char)" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs index d76711fce..665ead9a5 100644 --- a/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/Oracle/OdbcOracleExpression.cs @@ -99,8 +99,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs index c1be4f3ed..50147da1f 100644 --- a/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/PostgreSQL/OdbcPostgreSQLExpression.cs @@ -98,8 +98,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs index a8f882fc2..eea094838 100644 --- a/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs +++ b/Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerExpression.cs @@ -103,8 +103,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? (gentype2 == typeof(Guid) ? + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? (gentype2 == typeof(Guid) ? $"cast({getExp(callExp.Object)} as varchar(36))" : $"cast({getExp(callExp.Object)} as nvarchar{(gentype2.IsNumberType() || gentype2.IsEnum ? "(100)" : "(max)")})") : null; } diff --git a/Providers/FreeSql.Provider.Oracle/OracleExpression.cs b/Providers/FreeSql.Provider.Oracle/OracleExpression.cs index d1a81ecb4..7fe6a51ae 100644 --- a/Providers/FreeSql.Provider.Oracle/OracleExpression.cs +++ b/Providers/FreeSql.Provider.Oracle/OracleExpression.cs @@ -99,8 +99,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"to_char({getExp(callExp.Object)})" : null; } return null; } diff --git a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs index 17bfca7bc..6b5e52876 100644 --- a/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs +++ b/Providers/FreeSql.Provider.PostgreSQL/PostgreSQLExpression.cs @@ -99,8 +99,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; } return null; } diff --git a/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs b/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs index c3932471a..41b5df010 100644 --- a/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs +++ b/Providers/FreeSql.Provider.QuestDb/QuestDbExpression.cs @@ -104,8 +104,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as string)" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as string)" : null; } return null; } diff --git a/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs b/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs index c6c3601df..d4f4ed25e 100644 --- a/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs +++ b/Providers/FreeSql.Provider.ShenTong/ShenTongExpression.cs @@ -98,8 +98,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"({getExp(callExp.Object)})::text" : null; } return null; } diff --git a/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs b/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs index fc3af82ed..3d3b6a95e 100644 --- a/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs +++ b/Providers/FreeSql.Provider.SqlServer/SqlServerExpression.cs @@ -102,8 +102,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? (gentype2 == typeof(Guid) ? + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? (gentype2 == typeof(Guid) ? $"cast({getExp(callExp.Object)} as varchar(36))" : $"cast({getExp(callExp.Object)} as nvarchar{(gentype2.IsNumberType() || gentype2.IsEnum ? "(100)" : "(max)")})") : null; } diff --git a/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs b/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs index d1bcb6f58..7a4b2b68e 100644 --- a/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs +++ b/Providers/FreeSql.Provider.Sqlite/SqliteExpression.cs @@ -95,8 +95,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as character)" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as character)" : null; } return null; } diff --git a/Providers/FreeSql.Provider.Xugu/XuguExpression.cs b/Providers/FreeSql.Provider.Xugu/XuguExpression.cs index 2c927b6b3..b6f7c35df 100644 --- a/Providers/FreeSql.Provider.Xugu/XuguExpression.cs +++ b/Providers/FreeSql.Provider.Xugu/XuguExpression.cs @@ -102,8 +102,10 @@ public override string ExpressionLambdaToSqlOther(Expression exp, ExpTSC tsc) var enumStr = ExpressionLambdaToSql(callExp.Object, tsc); tsc.SetMapColumnTmp(null).SetMapTypeReturnOld(oldMapType); return enumStr; - } - return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as text)" : null; + } + var value = ExpressionGetValue(callExp.Object, out var success); + if (success) return formatSql(value, typeof(string), null, null); + return callExp.Arguments.Count == 0 ? $"cast({getExp(callExp.Object)} as text)" : null; } return null; }