Browse Source

Synchronization code

pull/29/head
sunkaixuan 2 years ago
parent
commit
646e44e1a2
  1. 1
      Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs
  2. 34
      Src/Asp.NetCore2/SqlSugar/Infrastructure/ContextMethods.cs
  3. 1
      Src/Asp.NetCore2/SqlSugar/Interface/IContextMethods.cs
  4. 6
      Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs

1
Src/Asp.Net/SqlSugar/Interface/IContextMethods.cs

@ -34,6 +34,7 @@ namespace SqlSugar
dynamic DataTableToDynamic(DataTable table); dynamic DataTableToDynamic(DataTable table);
List<T> DataTableToList<T>(DataTable table); List<T> DataTableToList<T>(DataTable table);
DataTable ListToDataTable<T>(List<T> list); DataTable ListToDataTable<T>(List<T> list);
DataTable ListToDataTableWithAttr<T>(List<T> list);
Dictionary<string, object> DataTableToDictionary(DataTable table); Dictionary<string, object> DataTableToDictionary(DataTable table);
List<Dictionary<string, object>> DataTableToDictionaryList(DataTable table); List<Dictionary<string, object>> DataTableToDictionaryList(DataTable table);
ICacheService GetReflectionInoCacheInstance(); ICacheService GetReflectionInoCacheInstance();

34
Src/Asp.NetCore2/SqlSugar/Infrastructure/ContextMethods.cs

@ -816,6 +816,40 @@ namespace SqlSugar
} }
return result; return result;
} }
public DataTable ListToDataTableWithAttr<T>(List<T> list)
{
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo<T>();
DataTable result = new DataTable();
result.TableName = entityInfo.DbTableName;
if (list != null && list.Count > 0)
{
var colimnInfos = entityInfo.Columns.Where(it=>it.IsIgnore==false);
foreach (var pi in colimnInfos)
{
//获取类型
Type colType = pi.PropertyInfo.PropertyType;
//当类型为Nullable<>时
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
result.Columns.Add(pi.DbColumnName, colType);
}
for (int i = 0; i < list.Count; i++)
{
ArrayList tempList = new ArrayList();
foreach (var pi in colimnInfos)
{
object obj = pi.PropertyInfo.GetValue(list[i], null);
tempList.Add(obj);
}
object[] array = tempList.ToArray();
result.LoadDataRow(array, true);
}
}
return result;
}
public Dictionary<string, object> DataTableToDictionary(DataTable table) public Dictionary<string, object> DataTableToDictionary(DataTable table)
{ {
return table.Rows.Cast<DataRow>().ToDictionary(x => x[0].ToString(), x => x[1]); return table.Rows.Cast<DataRow>().ToDictionary(x => x[0].ToString(), x => x[1]);

1
Src/Asp.NetCore2/SqlSugar/Interface/IContextMethods.cs

@ -34,6 +34,7 @@ namespace SqlSugar
dynamic DataTableToDynamic(DataTable table); dynamic DataTableToDynamic(DataTable table);
List<T> DataTableToList<T>(DataTable table); List<T> DataTableToList<T>(DataTable table);
DataTable ListToDataTable<T>(List<T> list); DataTable ListToDataTable<T>(List<T> list);
DataTable ListToDataTableWithAttr<T>(List<T> list);
Dictionary<string, object> DataTableToDictionary(DataTable table); Dictionary<string, object> DataTableToDictionary(DataTable table);
List<Dictionary<string, object>> DataTableToDictionaryList(DataTable table); List<Dictionary<string, object>> DataTableToDictionaryList(DataTable table);
ICacheService GetReflectionInoCacheInstance(); ICacheService GetReflectionInoCacheInstance();

6
Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs

@ -19,7 +19,11 @@ namespace SqlSugar
{ {
public static string ToUnderLine(string str, bool isToUpper = false) public static string ToUnderLine(string str, bool isToUpper = false)
{ {
if (isToUpper) if (str == null || str.Contains("_"))
{
return str;
}
else if (isToUpper)
{ {
return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString())).ToUpper(); return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString())).ToUpper();
} }

Loading…
Cancel
Save