Update CodeFirst

This commit is contained in:
sunkaixuan 2022-11-14 01:02:49 +08:00
parent 3f39f1c828
commit 7ab606176b
3 changed files with 42 additions and 1 deletions

View File

@ -19,7 +19,7 @@ namespace SqlSugar
public virtual string GetDbTypeName(string csharpTypeName)
{
if (csharpTypeName == UtilConstants.ByteArrayType.Name)
return "bytea";
return "varbinary";
if (csharpTypeName.ToLower() == "int32")
csharpTypeName = "int";
if (csharpTypeName.ToLower() == "int16")

View File

@ -6,6 +6,26 @@ namespace SqlSugar
{
public class PostgreSQLDbBind : DbBindProvider
{
public override string GetDbTypeName(string csharpTypeName)
{
if (csharpTypeName == UtilConstants.ByteArrayType.Name)
return "bytea";
if (csharpTypeName.ToLower() == "int32")
csharpTypeName = "int";
if (csharpTypeName.ToLower() == "int16")
csharpTypeName = "short";
if (csharpTypeName.ToLower() == "int64")
csharpTypeName = "long";
if (csharpTypeName.ToLower().IsIn("boolean", "bool"))
csharpTypeName = "bool";
if (csharpTypeName == "DateTimeOffset")
csharpTypeName = "DateTime";
var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase)).ToList();
if (mappings != null && mappings.Count > 0)
return mappings.First().Key;
else
return "varchar";
}
public override string GetPropertyTypeName(string dbTypeName)
{
dbTypeName = dbTypeName.ToLower();

View File

@ -30,5 +30,26 @@ namespace SqlSugar
return table;
}
}
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
{
var name = GetType(propertyType.Name);
if (name == "varbinary" && item.Length == 0)
{
name = "varbinary(max)";
}
result.DataType = this.Context.Ado.DbBind.GetDbTypeName(name);
}
}
}
}