mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-17 01:46:18 +08:00
Synchronization code
This commit is contained in:
parent
82a0221c48
commit
3a66dba6be
@ -41,6 +41,17 @@ namespace SqlSugar
|
|||||||
var mappings = this.MappingTypes.Where(it => it.Key == dbTypeName);
|
var mappings = this.MappingTypes.Where(it => it.Key == dbTypeName);
|
||||||
return mappings.HasValue() ? mappings.First().Key : "string";
|
return mappings.HasValue() ? mappings.First().Key : "string";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetCsharpTypeNameByDbTypeName(string dbTypeName)
|
||||||
|
{
|
||||||
|
var mappings = this.MappingTypes.Where(it => it.Key == dbTypeName);
|
||||||
|
if (mappings == null || mappings.Count() == 0)
|
||||||
|
{
|
||||||
|
return "string";
|
||||||
|
}
|
||||||
|
var result = mappings.First().Value.ObjToString();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
public virtual string GetConvertString(string dbTypeName)
|
public virtual string GetConvertString(string dbTypeName)
|
||||||
{
|
{
|
||||||
string result = string.Empty;
|
string result = string.Empty;
|
||||||
|
@ -103,6 +103,7 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
if (this.IsSingle)
|
if (this.IsSingle)
|
||||||
{
|
{
|
||||||
|
var isDic = this.EntityInfo.DbTableName.StartsWith("Dictionary`");
|
||||||
foreach (var item in this.InsertBuilder.DbColumnInfoList)
|
foreach (var item in this.InsertBuilder.DbColumnInfoList)
|
||||||
{
|
{
|
||||||
if (this.InsertBuilder.Parameters == null) this.InsertBuilder.Parameters = new List<SugarParameter>();
|
if (this.InsertBuilder.Parameters == null) this.InsertBuilder.Parameters = new List<SugarParameter>();
|
||||||
@ -119,6 +120,15 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
paramters.IsArray = true;
|
paramters.IsArray = true;
|
||||||
}
|
}
|
||||||
|
if (item.Value == null && isDic)
|
||||||
|
{
|
||||||
|
var type = this.SqlBuilder.GetNullType(this.InsertBuilder.GetTableNameString, item.DbColumnName);
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
paramters = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, type);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
this.InsertBuilder.Parameters.Add(paramters);
|
this.InsertBuilder.Parameters.Add(paramters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,6 +363,10 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return sql;
|
return sql;
|
||||||
}
|
}
|
||||||
|
public virtual Type GetNullType(string tableName,string columnName)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
private void BuilderTree(StringBuilder builder,ConditionalTree item,ref int indexTree, List<SugarParameter> parameters,ref int mainIndex)
|
private void BuilderTree(StringBuilder builder,ConditionalTree item,ref int indexTree, List<SugarParameter> parameters,ref int mainIndex)
|
||||||
{
|
{
|
||||||
var conditionals = ToConditionalCollections(item,ref indexTree, parameters);
|
var conditionals = ToConditionalCollections(item,ref indexTree, parameters);
|
||||||
|
@ -268,6 +268,7 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
if (this.IsSingle)
|
if (this.IsSingle)
|
||||||
{
|
{
|
||||||
|
var isDic = this.EntityInfo.DbTableName.StartsWith("Dictionary`");
|
||||||
foreach (var item in this.UpdateBuilder.DbColumnInfoList)
|
foreach (var item in this.UpdateBuilder.DbColumnInfoList)
|
||||||
{
|
{
|
||||||
if (this.UpdateBuilder.Parameters == null) this.UpdateBuilder.Parameters = new List<SugarParameter>();
|
if (this.UpdateBuilder.Parameters == null) this.UpdateBuilder.Parameters = new List<SugarParameter>();
|
||||||
@ -284,6 +285,14 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
parameter.IsArray = true;
|
parameter.IsArray = true;
|
||||||
}
|
}
|
||||||
|
if (item.Value == null && isDic)
|
||||||
|
{
|
||||||
|
var type = this.SqlBuilder.GetNullType(this.UpdateBuilder.GetTableNameString, item.DbColumnName);
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
parameter = new SugarParameter(this.SqlBuilder.SqlParameterKeyWord + item.DbColumnName, item.Value, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
this.UpdateBuilder.Parameters.Add(parameter);
|
this.UpdateBuilder.Parameters.Add(parameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ namespace SqlSugar
|
|||||||
string GetConvertString(string dbTypeName);
|
string GetConvertString(string dbTypeName);
|
||||||
string GetDbTypeName(string csharpTypeName);
|
string GetDbTypeName(string csharpTypeName);
|
||||||
string GetCsharpTypeName(string dbTypeName);
|
string GetCsharpTypeName(string dbTypeName);
|
||||||
|
string GetCsharpTypeNameByDbTypeName(string dbTypeName);
|
||||||
List<KeyValuePair<string, CSharpDataType>> MappingTypes { get; }
|
List<KeyValuePair<string, CSharpDataType>> MappingTypes { get; }
|
||||||
List<T> DataReaderToList<T>(Type type, IDataReader reader);
|
List<T> DataReaderToList<T>(Type type, IDataReader reader);
|
||||||
Task<List<T>> DataReaderToListAsync<T>(Type entityType, IDataReader dataReader);
|
Task<List<T>> DataReaderToListAsync<T>(Type entityType, IDataReader dataReader);
|
||||||
|
@ -42,5 +42,6 @@ namespace SqlSugar
|
|||||||
void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex);
|
void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex);
|
||||||
KeyValuePair<string, SugarParameter[]> ConditionalModelToSql(List<IConditionalModel> models, int beginIndex = 0);
|
KeyValuePair<string, SugarParameter[]> ConditionalModelToSql(List<IConditionalModel> models, int beginIndex = 0);
|
||||||
string GetUnionFomatSql(string sql);
|
string GetUnionFomatSql(string sql);
|
||||||
|
Type GetNullType(string tableName,string columnName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,5 +102,21 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
return " ( " + sql + " ) ";
|
return " ( " + sql + " ) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Type GetNullType(string tableName, string columnName)
|
||||||
|
{
|
||||||
|
var columnInfo=this.Context.DbMaintenance.GetColumnInfosByTableName(tableName).FirstOrDefault(z => z.DbColumnName.EqualCase(columnName));
|
||||||
|
if (columnInfo != null)
|
||||||
|
{
|
||||||
|
var cTypeName=this.Context.Ado.DbBind.GetCsharpTypeNameByDbTypeName(columnInfo.DataType);
|
||||||
|
var value=UtilMethods.GetTypeByTypeName(cTypeName);
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
var key = "GetNullType_" + tableName + columnName;
|
||||||
|
return new ReflectionInoCacheService().GetOrCreate(key, () => value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -636,6 +636,103 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return dic;
|
return dic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Type GetTypeByTypeName(string ctypename)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (ctypename.EqualCase(UtilConstants.DecType.Name))
|
||||||
|
{
|
||||||
|
return UtilConstants.DecType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase(UtilConstants.DobType.Name))
|
||||||
|
{
|
||||||
|
return UtilConstants.DobType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase(UtilConstants.DateType.Name))
|
||||||
|
{
|
||||||
|
return UtilConstants.DateType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase(UtilConstants.IntType.Name))
|
||||||
|
{
|
||||||
|
return UtilConstants.IntType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase(UtilConstants.BoolType.Name))
|
||||||
|
{
|
||||||
|
return UtilConstants.BoolType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase(UtilConstants.LongType.Name))
|
||||||
|
{
|
||||||
|
return UtilConstants.LongType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase(UtilConstants.ShortType.Name))
|
||||||
|
{
|
||||||
|
return UtilConstants.ShortType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase(UtilConstants.DateTimeOffsetType.Name))
|
||||||
|
{
|
||||||
|
return UtilConstants.DateTimeOffsetType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase(UtilConstants.GuidType.Name))
|
||||||
|
{
|
||||||
|
return UtilConstants.GuidType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("int"))
|
||||||
|
{
|
||||||
|
return UtilConstants.IntType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("long"))
|
||||||
|
{
|
||||||
|
return UtilConstants.LongType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("short"))
|
||||||
|
{
|
||||||
|
return UtilConstants.ShortType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("byte"))
|
||||||
|
{
|
||||||
|
return UtilConstants.ByteType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("uint"))
|
||||||
|
{
|
||||||
|
return UtilConstants.UIntType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("ulong"))
|
||||||
|
{
|
||||||
|
return UtilConstants.ULongType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("ushort"))
|
||||||
|
{
|
||||||
|
return UtilConstants.UShortType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("uint32"))
|
||||||
|
{
|
||||||
|
return UtilConstants.UIntType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("uint64"))
|
||||||
|
{
|
||||||
|
return UtilConstants.ULongType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("bool"))
|
||||||
|
{
|
||||||
|
return UtilConstants.BoolType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("ToBoolean"))
|
||||||
|
{
|
||||||
|
return UtilConstants.BoolType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase("uint16"))
|
||||||
|
{
|
||||||
|
return UtilConstants.UShortType;
|
||||||
|
}
|
||||||
|
else if (ctypename.EqualCase(UtilConstants.ByteArrayType.Name))
|
||||||
|
{
|
||||||
|
return UtilConstants.ByteArrayType;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return UtilConstants.StringType;
|
||||||
|
}
|
||||||
|
}
|
||||||
public static object ConvertDataByTypeName(string ctypename,string value)
|
public static object ConvertDataByTypeName(string ctypename,string value)
|
||||||
{
|
{
|
||||||
var item = new ConditionalModel() {
|
var item = new ConditionalModel() {
|
||||||
|
Loading…
Reference in New Issue
Block a user