CodeFirst BUG

This commit is contained in:
sunkaixuna 2021-05-15 22:17:39 +08:00
parent d51cd36e98
commit dda289c7cc
3 changed files with 29 additions and 2 deletions

View File

@ -1,4 +1,5 @@
using System; using SqlSugar;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -34,6 +35,13 @@ namespace OrmTest
id=it.a, id=it.a,
b=it.b b=it.b
}).ToList(); }).ToList();
Db.CodeFirst.InitTables<UnitTest012213>();
}
public class UnitTest012213
{
[SugarColumn(ColumnDataType = "image,longblob")]
public byte[] x { get; set; }
} }
public class UnitCodeTest1 public class UnitCodeTest1
{ {

View File

@ -1,4 +1,5 @@
using System; using SqlSugar;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -22,8 +23,14 @@ namespace OrmTest
}; };
Db.CodeFirst.InitTables<UnitCodeFirstpks3>(); Db.CodeFirst.InitTables<UnitCodeFirstpks3>();
Db.CodeFirst.InitTables<UnitCodeFirstpks32>(); Db.CodeFirst.InitTables<UnitCodeFirstpks32>();
db.CodeFirst.InitTables<UnitTest0122132>();
} }
public class UnitTest0122132
{
[SugarColumn(ColumnDataType = "image,longblob")]
public byte[] x { get; set; }
}
[SqlSugar.SugarTable("[dbo].[UnitCodeFirstpks3aaa122]")] [SqlSugar.SugarTable("[dbo].[UnitCodeFirstpks3aaa122]")]
public class UnitCodeFirstpks32 public class UnitCodeFirstpks32
{ {

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
namespace SqlSugar namespace SqlSugar
{ {
public partial class CodeFirstProvider : ICodeFirst public partial class CodeFirstProvider : ICodeFirst
@ -114,6 +116,16 @@ namespace SqlSugar
{ {
item.Length = DefultLength; 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); var tableName = GetTableName(entityInfo);