diff --git a/Examples/restful/Startup.cs b/Examples/restful/Startup.cs index ac6c5817..3cc16581 100644 --- a/Examples/restful/Startup.cs +++ b/Examples/restful/Startup.cs @@ -17,6 +17,18 @@ namespace restful { .UseLogger(loggerFactory.CreateLogger()) .UseAutoSyncStructure(true) .Build(); + + Fsql.Aop.CurdAfter = (s, e) => { + if (e.ElapsedMilliseconds > 200) { + //记录日志 + //发送短信给负责人 + } + }; + + //Fsql.Aop.Where = (s, e) => { + // if (e.Parameters[0]?.ToString() == "1") + // e.IsCancel = true; + //}; } public IConfiguration Configuration { get; } diff --git a/FreeSql.Tests/UnitTest1.cs b/FreeSql.Tests/UnitTest1.cs index 2217f07a..016444be 100644 --- a/FreeSql.Tests/UnitTest1.cs +++ b/FreeSql.Tests/UnitTest1.cs @@ -126,7 +126,7 @@ namespace FreeSql.Tests { [Fact] public void Test1() { - g.sqlite.CodeFirst.SyncStructure(); + Assert.Throws(() => g.sqlite.CodeFirst.SyncStructure()); var TestEnumable = new TestEnumable(); diff --git a/FreeSql/FreeSql.csproj b/FreeSql/FreeSql.csproj index 66288a1a..bbc28275 100644 --- a/FreeSql/FreeSql.csproj +++ b/FreeSql/FreeSql.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 0.5.22 + 0.5.23 true YeXiangQin FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite. @@ -18,7 +18,7 @@ - C:\Users\28810\Desktop\github\FreeSql\FreeSql\FreeSql.xml + FreeSql.xml 3 diff --git a/FreeSql/Internal/UtilsExpressionTree.cs b/FreeSql/Internal/UtilsExpressionTree.cs index 6fa879d1..6b71f42b 100644 --- a/FreeSql/Internal/UtilsExpressionTree.cs +++ b/FreeSql/Internal/UtilsExpressionTree.cs @@ -109,11 +109,6 @@ namespace FreeSql.Internal { if (tmpLt.Contains("BYTE")) tmpLt = tmpLt.Replace("BYTE", " BYTE"); return tmpLt; }); - colattr.DbDefautValue = trytb.Properties[p.Name].GetValue(Activator.CreateInstance(trytb.Type)); - if (colattr.DbDefautValue != null && p.PropertyType != colattr.MapType) colattr.DbDefautValue = Utils.GetDataReaderValue(colattr.MapType, colattr.DbDefautValue); - if (colattr.DbDefautValue == null) colattr.DbDefautValue = tp?.defaultValue; - if (colattr.IsNullable == false && colattr.DbDefautValue == null) - colattr.DbDefautValue = Activator.CreateInstance(colattr.MapType.IsNullableType() ? colattr.MapType.GenericTypeArguments.FirstOrDefault() : colattr.MapType); if (colattr.IsIdentity == true && colattr.MapType.IsNumberType() == false) colattr.IsIdentity = false; if (setMethod == null) colattr.IsIgnore = true; @@ -128,6 +123,17 @@ namespace FreeSql.Internal { trytb.ColumnsByCsIgnore.Add(p.Name, col); continue; } + colattr.DbDefautValue = trytb.Properties[p.Name].GetValue(Activator.CreateInstance(trytb.Type)); + if (colattr.DbDefautValue != null && p.PropertyType != colattr.MapType) colattr.DbDefautValue = Utils.GetDataReaderValue(colattr.MapType, colattr.DbDefautValue); + if (colattr.DbDefautValue == null) colattr.DbDefautValue = tp?.defaultValue; + if (colattr.IsNullable == false && colattr.DbDefautValue == null) { + var citype = colattr.MapType.IsNullableType() ? colattr.MapType.GenericTypeArguments.FirstOrDefault() : colattr.MapType; + if (citype.IsArray) + colattr.DbDefautValue = Array.CreateInstance(citype, 0); + else + colattr.DbDefautValue = Activator.CreateInstance(citype); + } + trytb.Columns.Add(colattr.Name, col); trytb.ColumnsByCs.Add(p.Name, col); } diff --git a/FreeSql/MySql/MySqlExpression.cs b/FreeSql/MySql/MySqlExpression.cs index a8664080..f6634806 100644 --- a/FreeSql/MySql/MySqlExpression.cs +++ b/FreeSql/MySql/MySqlExpression.cs @@ -18,8 +18,8 @@ namespace FreeSql.MySql { case ExpressionType.Convert: var operandExp = (exp as UnaryExpression)?.Operand; var gentype = exp.Type.NullableTypeOrThis(); - if (gentype != exp.Type.NullableTypeOrThis()) { - switch (exp.Type.NullableTypeOrThis().ToString()) { + if (gentype != operandExp.Type.NullableTypeOrThis()) { + switch (gentype.ToString()) { case "System.Boolean": return $"({getExp(operandExp)} not in ('0','false'))"; case "System.Byte": return $"cast({getExp(operandExp)} as unsigned)"; case "System.Char": return $"substr(cast({getExp(operandExp)} as char), 1, 1)"; diff --git a/FreeSql/Oracle/OracleExpression.cs b/FreeSql/Oracle/OracleExpression.cs index 6dde4826..8003f125 100644 --- a/FreeSql/Oracle/OracleExpression.cs +++ b/FreeSql/Oracle/OracleExpression.cs @@ -18,7 +18,7 @@ namespace FreeSql.Oracle { case ExpressionType.Convert: var operandExp = (exp as UnaryExpression)?.Operand; var gentype = exp.Type.NullableTypeOrThis(); - if (gentype != exp.Type.NullableTypeOrThis()) { + if (gentype != operandExp.Type.NullableTypeOrThis()) { switch (exp.Type.NullableTypeOrThis().ToString()) { //case "System.Boolean": return $"({getExp(operandExp)} not in ('0','false'))"; case "System.Byte": return $"cast({getExp(operandExp)} as number)"; diff --git a/FreeSql/PostgreSQL/PostgreSQLExpression.cs b/FreeSql/PostgreSQL/PostgreSQLExpression.cs index 4673d767..2fe5abc5 100644 --- a/FreeSql/PostgreSQL/PostgreSQLExpression.cs +++ b/FreeSql/PostgreSQL/PostgreSQLExpression.cs @@ -19,7 +19,7 @@ namespace FreeSql.PostgreSQL { case ExpressionType.Convert: var operandExp = (exp as UnaryExpression)?.Operand; var gentype = exp.Type.NullableTypeOrThis(); - if (gentype != exp.Type.NullableTypeOrThis()) { + if (gentype != operandExp.Type.NullableTypeOrThis()) { switch (exp.Type.NullableTypeOrThis().ToString()) { case "System.Boolean": return $"(({getExp(operandExp)})::varchar not in ('0','false','f','no'))"; case "System.Byte": return $"({getExp(operandExp)})::int2"; diff --git a/FreeSql/SqlServer/SqlServerExpression.cs b/FreeSql/SqlServer/SqlServerExpression.cs index 83cfe810..0dc8e19b 100644 --- a/FreeSql/SqlServer/SqlServerExpression.cs +++ b/FreeSql/SqlServer/SqlServerExpression.cs @@ -18,7 +18,7 @@ namespace FreeSql.SqlServer { case ExpressionType.Convert: var operandExp = (exp as UnaryExpression)?.Operand; var gentype = exp.Type.NullableTypeOrThis(); - if (gentype != exp.Type.NullableTypeOrThis()) { + if (gentype != operandExp.Type.NullableTypeOrThis()) { switch (gentype.ToString()) { case "System.Boolean": return $"(cast({getExp(operandExp)} as varchar) not in ('0','false'))"; case "System.Byte": return $"cast({getExp(operandExp)} as tinyint)"; diff --git a/FreeSql/Sqlite/SqliteExpression.cs b/FreeSql/Sqlite/SqliteExpression.cs index 97d2f80c..4af0e9d1 100644 --- a/FreeSql/Sqlite/SqliteExpression.cs +++ b/FreeSql/Sqlite/SqliteExpression.cs @@ -18,7 +18,7 @@ namespace FreeSql.Sqlite { case ExpressionType.Convert: var operandExp = (exp as UnaryExpression)?.Operand; var gentype = exp.Type.NullableTypeOrThis(); - if (gentype != exp.Type.NullableTypeOrThis()) { + if (gentype != operandExp.Type.NullableTypeOrThis()) { switch (exp.Type.NullableTypeOrThis().ToString()) { case "System.Boolean": return $"({getExp(operandExp)} not in ('0','false'))"; case "System.Byte": return $"cast({getExp(operandExp)} as int2)";