From f3eab9be9b0746dec80ce72697f07b765630354f Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sat, 1 Jul 2023 23:22:42 +0800 Subject: [PATCH] =?UTF-8?q?Updated=20=20=E8=BE=BE=E6=A2=A6=20CodeFirst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Realization/Dm/CodeFirst/DmCodeFirst.cs | 26 +++++++++++++++++++ .../Realization/Dm/DbBind/DmDbBind.cs | 2 ++ .../Oracle/CodeFirst/OracleCodeFirst.cs | 4 +++ 3 files changed, 32 insertions(+) diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/Dm/CodeFirst/DmCodeFirst.cs b/Src/Asp.NetCore2/SqlSugar/Realization/Dm/CodeFirst/DmCodeFirst.cs index 143e79240..3a14da721 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/Dm/CodeFirst/DmCodeFirst.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/Dm/CodeFirst/DmCodeFirst.cs @@ -50,6 +50,32 @@ namespace SqlSugar } return result; } + protected override void GetDbType(EntityColumnInfo item, Type propertyType, DbColumnInfo result) + { + if (!string.IsNullOrEmpty(item.DataType)) + { + result.DataType = item.DataType; + } + else if (propertyType.IsEnum()) + { + result.DataType = this.Context.Ado.DbBind.GetDbTypeName(item.Length > 9 ? UtilConstants.LongType.Name : UtilConstants.IntType.Name); + } + else + { + if (propertyType.Name.Equals("Guid", StringComparison.CurrentCultureIgnoreCase)) + { + result.DataType = this.Context.Ado.DbBind.GetDbTypeName(UtilConstants.StringType.Name); + if (result.Length <= 1) + { + result.Length = 36; + } + } + else + { + result.DataType = this.Context.Ado.DbBind.GetDbTypeName(propertyType.Name); + } + } + } protected override void ConvertColumns(List dbColumns) { diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/Dm/DbBind/DmDbBind.cs b/Src/Asp.NetCore2/SqlSugar/Realization/Dm/DbBind/DmDbBind.cs index 7e59503d8..a13d912f5 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/Dm/DbBind/DmDbBind.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/Dm/DbBind/DmDbBind.cs @@ -18,6 +18,8 @@ namespace SqlSugar csharpTypeName = "long"; if (csharpTypeName.ToLower().IsIn("boolean", "bool")) csharpTypeName = "bool"; + if (csharpTypeName == "Guid") + csharpTypeName = "string"; if (csharpTypeName == "DateTimeOffset") csharpTypeName = "DateTime"; var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase)); diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/CodeFirst/OracleCodeFirst.cs b/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/CodeFirst/OracleCodeFirst.cs index 3d7cafbe2..0f8d499eb 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/CodeFirst/OracleCodeFirst.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/Oracle/CodeFirst/OracleCodeFirst.cs @@ -28,6 +28,10 @@ namespace SqlSugar if (propertyType.Name.Equals("Guid", StringComparison.CurrentCultureIgnoreCase)) { result.DataType = this.Context.Ado.DbBind.GetDbTypeName(UtilConstants.StringType.Name); + if (result.Length <= 1) + { + result.Length = 36; + } } else {