mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Add json default data type
This commit is contained in:
@@ -12,6 +12,7 @@ namespace OrmTest
|
|||||||
public static void Json()
|
public static void Json()
|
||||||
{
|
{
|
||||||
Db.CodeFirst.InitTables<UnitJsonTest>();
|
Db.CodeFirst.InitTables<UnitJsonTest>();
|
||||||
|
Db.CodeFirst.InitTables<UnitJsonTest2>();
|
||||||
Db.DbMaintenance.TruncateTable<UnitJsonTest>();
|
Db.DbMaintenance.TruncateTable<UnitJsonTest>();
|
||||||
Db.Insertable(new UnitJsonTest() { Order = new Order { Id = 1, Name = "order1" } }).ExecuteCommand();
|
Db.Insertable(new UnitJsonTest() { Order = new Order { Id = 1, Name = "order1" } }).ExecuteCommand();
|
||||||
var list = Db.Queryable<UnitJsonTest>().ToList();
|
var list = Db.Queryable<UnitJsonTest>().ToList();
|
||||||
@@ -23,7 +24,13 @@ namespace OrmTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UnitJsonTest2
|
||||||
|
{
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[SqlSugar.SugarColumn(IsJson = true)]
|
||||||
|
public Order Order { get; set; }
|
||||||
|
}
|
||||||
public class UnitJsonTest
|
public class UnitJsonTest
|
||||||
{
|
{
|
||||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||||
|
@@ -175,6 +175,17 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (sugarColumn.IsJson && String.IsNullOrEmpty(sugarColumn.ColumnDataType))
|
||||||
|
{
|
||||||
|
if (this.Context.CurrentConnectionConfig.DbType == DbType.PostgreSQL)
|
||||||
|
{
|
||||||
|
column.DataType = "json";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
column.DataType = "varchar(4000)";
|
||||||
|
}
|
||||||
|
}
|
||||||
if (sugarColumn.IsIgnore == false)
|
if (sugarColumn.IsIgnore == false)
|
||||||
{
|
{
|
||||||
column.DbColumnName = sugarColumn.ColumnName.IsNullOrEmpty() ? property.Name : sugarColumn.ColumnName;
|
column.DbColumnName = sugarColumn.ColumnName.IsNullOrEmpty() ? property.Name : sugarColumn.ColumnName;
|
||||||
|
Reference in New Issue
Block a user