mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +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);
|
||||
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)
|
||||
{
|
||||
string result = string.Empty;
|
||||
|
@ -103,6 +103,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
if (this.IsSingle)
|
||||
{
|
||||
var isDic = this.EntityInfo.DbTableName.StartsWith("Dictionary`");
|
||||
foreach (var item in this.InsertBuilder.DbColumnInfoList)
|
||||
{
|
||||
if (this.InsertBuilder.Parameters == null) this.InsertBuilder.Parameters = new List<SugarParameter>();
|
||||
@ -119,6 +120,15 @@ namespace SqlSugar
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -363,6 +363,10 @@ namespace SqlSugar
|
||||
{
|
||||
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)
|
||||
{
|
||||
var conditionals = ToConditionalCollections(item,ref indexTree, parameters);
|
||||
|
@ -268,6 +268,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
if (this.IsSingle)
|
||||
{
|
||||
var isDic = this.EntityInfo.DbTableName.StartsWith("Dictionary`");
|
||||
foreach (var item in this.UpdateBuilder.DbColumnInfoList)
|
||||
{
|
||||
if (this.UpdateBuilder.Parameters == null) this.UpdateBuilder.Parameters = new List<SugarParameter>();
|
||||
@ -284,6 +285,14 @@ namespace SqlSugar
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ namespace SqlSugar
|
||||
string GetConvertString(string dbTypeName);
|
||||
string GetDbTypeName(string csharpTypeName);
|
||||
string GetCsharpTypeName(string dbTypeName);
|
||||
string GetCsharpTypeNameByDbTypeName(string dbTypeName);
|
||||
List<KeyValuePair<string, CSharpDataType>> MappingTypes { get; }
|
||||
List<T> DataReaderToList<T>(Type type, IDataReader reader);
|
||||
Task<List<T>> DataReaderToListAsync<T>(Type entityType, IDataReader dataReader);
|
||||
|
@ -42,5 +42,6 @@ namespace SqlSugar
|
||||
void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex);
|
||||
KeyValuePair<string, SugarParameter[]> ConditionalModelToSql(List<IConditionalModel> models, int beginIndex = 0);
|
||||
string GetUnionFomatSql(string sql);
|
||||
Type GetNullType(string tableName,string columnName);
|
||||
}
|
||||
}
|
||||
|
@ -102,5 +102,21 @@ namespace SqlSugar
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
var item = new ConditionalModel() {
|
||||
|
Loading…
Reference in New Issue
Block a user