Support PgSql Json

This commit is contained in:
skx
2020-10-02 13:54:49 +08:00
parent b2aebdaa21
commit 92d00016ff
5 changed files with 20 additions and 2 deletions

View File

@@ -29,8 +29,11 @@ namespace SqlSugar
csharpTypeName = "long";
if (csharpTypeName.ToLower().IsIn("boolean", "bool"))
csharpTypeName = "bool";
var mappings = this.MappingTypes.Where(it => it.Value.ToString().Equals(csharpTypeName, StringComparison.CurrentCultureIgnoreCase));
return mappings.HasValue() ? mappings.First().Key : "varchar";
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 string GetCsharpTypeName(string dbTypeName)
{

View File

@@ -339,6 +339,10 @@ namespace SqlSugar
{
continue;
}
if (item.IsJson)
{
paramters.IsJson = true;
}
this.InsertBuilder.Parameters.Add(paramters);
}
}
@@ -399,6 +403,10 @@ namespace SqlSugar
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
TableId = i
};
if (column.IsJson)
{
columnInfo.IsJson = true;
}
if (columnInfo.PropertyType.IsEnum())
{
columnInfo.Value = Convert.ToInt64(columnInfo.Value);

View File

@@ -21,5 +21,6 @@ namespace SqlSugar
public object Value { get; set; }
public int DecimalDigits { get; set; }
public int Scale { get; set; }
internal bool IsJson { get; set; }
}
}

View File

@@ -233,5 +233,6 @@ namespace SqlSugar
public string TypeName { get; set; }
public bool IsJson { get; set; }
}
}

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Npgsql;
using NpgsqlTypes;
namespace SqlSugar
{
@@ -94,6 +95,10 @@ namespace SqlSugar
sqlParameter.Value = parameter.Value;
sqlParameter.DbType = parameter.DbType;
sqlParameter.Direction = parameter.Direction;
if (parameter.IsJson)
{
sqlParameter.NpgsqlDbType = NpgsqlDbType.Json;
}
if (sqlParameter.Direction == 0)
{
sqlParameter.Direction = ParameterDirection.Input;