mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 优化 实体数据属性 DbDefaultValue 处理;
- 修复 Expression 表达式解析 Convert 的判断 bug;
This commit is contained in:
parent
d54b245ba5
commit
5d734052df
@ -17,6 +17,18 @@ namespace restful {
|
||||
.UseLogger(loggerFactory.CreateLogger<IFreeSql>())
|
||||
.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; }
|
||||
|
@ -126,7 +126,7 @@ namespace FreeSql.Tests {
|
||||
[Fact]
|
||||
public void Test1() {
|
||||
|
||||
g.sqlite.CodeFirst.SyncStructure<TestEnumable>();
|
||||
Assert.Throws<Exception>(() => g.sqlite.CodeFirst.SyncStructure<TestEnumable>());
|
||||
|
||||
var TestEnumable = new TestEnumable();
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.5.22</Version>
|
||||
<Version>0.5.23</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
||||
@ -18,7 +18,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>C:\Users\28810\Desktop\github\FreeSql\FreeSql\FreeSql.xml</DocumentationFile>
|
||||
<DocumentationFile>FreeSql.xml</DocumentationFile>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)";
|
||||
|
@ -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)";
|
||||
|
@ -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";
|
||||
|
@ -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)";
|
||||
|
@ -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)";
|
||||
|
Loading…
x
Reference in New Issue
Block a user