From dda289c7ccf45d581cd08ce52de564fa2dae1f24 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Sat, 15 May 2021 22:17:39 +0800 Subject: [PATCH] CodeFirst BUG --- Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs | 10 +++++++++- Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs | 9 ++++++++- .../Abstract/CodeFirstProvider/CodeFirstProvider.cs | 12 ++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs b/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs index bd3b4936f..1d90372bd 100644 --- a/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs +++ b/Src/Asp.Net/MySqlTest/UnitTest/UCodeFirst.cs @@ -1,4 +1,5 @@ -using System; +using SqlSugar; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -34,6 +35,13 @@ namespace OrmTest id=it.a, b=it.b }).ToList(); + Db.CodeFirst.InitTables(); + } + public class UnitTest012213 + { + + [SugarColumn(ColumnDataType = "image,longblob")] + public byte[] x { get; set; } } public class UnitCodeTest1 { diff --git a/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs b/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs index 5b763ce49..7c7887246 100644 --- a/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs +++ b/Src/Asp.Net/SqlServerTest/UnitTest/UCodeFirst.cs @@ -1,4 +1,5 @@ -using System; +using SqlSugar; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -22,8 +23,14 @@ namespace OrmTest }; Db.CodeFirst.InitTables(); Db.CodeFirst.InitTables(); + db.CodeFirst.InitTables(); } + public class UnitTest0122132 + { + [SugarColumn(ColumnDataType = "image,longblob")] + public byte[] x { get; set; } + } [SqlSugar.SugarTable("[dbo].[UnitCodeFirstpks3aaa122]")] public class UnitCodeFirstpks32 { diff --git a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs index dd48e8cd6..52ed59297 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; +using System.Text.RegularExpressions; + namespace SqlSugar { public partial class CodeFirstProvider : ICodeFirst @@ -114,6 +116,16 @@ namespace SqlSugar { item.Length = DefultLength; } + if (item.DataType!=null&&item.DataType.Contains(",")&& !Regex.IsMatch(item.DataType,@"\d\,\d")) + { + var types = item.DataType.Split(',').Select(it => it.ToLower()).ToList(); + var mapingTypes=this.Context.Ado.DbBind.MappingTypes.Select(it=>it.Key.ToLower()).ToList(); + var mappingType=types.FirstOrDefault(it => mapingTypes.Contains(it)); + if (mappingType != null) + { + item.DataType = mappingType; + } + } } } var tableName = GetTableName(entityInfo);