From d51aef2aa96b3d55a21ea659fb05509134f8b514 Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Fri, 6 Sep 2019 13:29:15 +0800 Subject: [PATCH] add test --- FreeSql.Tests/FreeSql.Tests/UnitTest1.cs | 6 ++++++ FreeSql/Extensions/FreeSqlGlobalExtensions.cs | 13 +++++++------ FreeSql/Internal/CommonExpression.cs | 5 +++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/FreeSql.Tests/FreeSql.Tests/UnitTest1.cs b/FreeSql.Tests/FreeSql.Tests/UnitTest1.cs index efc884c6..3df650fb 100644 --- a/FreeSql.Tests/FreeSql.Tests/UnitTest1.cs +++ b/FreeSql.Tests/FreeSql.Tests/UnitTest1.cs @@ -405,6 +405,12 @@ namespace FreeSql.Tests [Fact] public void Test1() { + var floorSql = g.sqlite.Select().Where(a => a.OptionsEntity04 / 10000 == 121212 / 10000).ToSql(); + + var testBoolSql1 = g.sqlserver.Select().Where(a => a.OptionsEntity01).ToSql(); + var testBoolSql2 = g.sqlserver.Select().Where(a => a.Id == Guid.NewGuid() && a.OptionsEntity01).ToSql(); + + IFreeSql fsql = new FreeSql.FreeSqlBuilder() .UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=7") .UseEntityPropertyNameConvert(Internal.StringConvertType.PascalCaseToUnderscoreWithLower) diff --git a/FreeSql/Extensions/FreeSqlGlobalExtensions.cs b/FreeSql/Extensions/FreeSqlGlobalExtensions.cs index 1c145a27..4611cd89 100644 --- a/FreeSql/Extensions/FreeSqlGlobalExtensions.cs +++ b/FreeSql/Extensions/FreeSqlGlobalExtensions.cs @@ -28,13 +28,14 @@ public static partial class FreeSqlGlobalExtensions [typeof(uint?)] = true, [typeof(ulong)] = true, [typeof(ulong?)] = true, - [typeof(double)] = true, - [typeof(double?)] = true, - [typeof(float)] = true, - [typeof(float?)] = true, - [typeof(decimal)] = true, - [typeof(decimal?)] = true + [typeof(double)] = false, + [typeof(double?)] = false, + [typeof(float)] = false, + [typeof(float?)] = false, + [typeof(decimal)] = false, + [typeof(decimal?)] = false }); + public static bool IsIntegerType(this Type that) => that == null ? false : (dicIsNumberType.Value.TryGetValue(that, out var tryval) ? tryval : false); public static bool IsNumberType(this Type that) => that == null ? false : dicIsNumberType.Value.ContainsKey(that); public static bool IsNullableType(this Type that) => that?.FullName.StartsWith("System.Nullable`1[") == true; public static bool IsAnonymousType(this Type that) => that?.FullName.StartsWith("<>f__AnonymousType") == true; diff --git a/FreeSql/Internal/CommonExpression.cs b/FreeSql/Internal/CommonExpression.cs index 63ab1906..6e54b362 100644 --- a/FreeSql/Internal/CommonExpression.cs +++ b/FreeSql/Internal/CommonExpression.cs @@ -387,6 +387,7 @@ namespace FreeSql.Internal static ConcurrentDictionary _dicFreeSqlGlobalExtensionsAsSelectExpression = new ConcurrentDictionary(); static MethodInfo MethodDateTimeSubtractDateTime = typeof(DateTime).GetMethod("Subtract", new Type[] { typeof(DateTime) }); static MethodInfo MethodDateTimeSubtractTimeSpan = typeof(DateTime).GetMethod("Subtract", new Type[] { typeof(TimeSpan) }); + static MethodInfo MethodMathFloor = typeof(Math).GetMethod("Floor", new Type[] { typeof(double) }); static string GetBoolString(string sql) { @@ -489,6 +490,10 @@ namespace FreeSql.Internal break; } tsc.mapType = null; + //switch(oper) + //{ + // case "/": return ExpressionLambdaToSqlCallMath(Expression.Call(MethodMathFloor, Expression.Constant(1213.1d, typeof(double))), tsc)?.Replace("1213.1", $"{left} {oper} {right}"); + //} return $"{left} {oper} {right}"; } public string ExpressionLambdaToSql(Expression exp, ExpTSC tsc)