Browse Source

Update core

pull/10/head
sunkaixuna 3 years ago
parent
commit
f71648f1da
  1. 13
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs
  2. 26
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerBlukCopy.cs
  3. 69
      Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/PropertyCallAdapterProvider.cs

13
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs

@ -620,14 +620,19 @@ namespace SqlSugar
foreach (var column in EntityInfo.Columns)
{
if (column.IsIgnore || column.IsOnlyIgnoreInsert) continue;
var isMapping = IsMappingColumns;
var columnInfo = new DbColumnInfo()
{
Value = column.PropertyInfo.GetValue(item, null),
DbColumnName = GetDbColumnName(column.PropertyName),
Value = PropertyCallAdapterProvider<T>.GetInstance(column.PropertyName).InvokeGet(item),
DbColumnName = column.DbColumnName,
PropertyName = column.PropertyName,
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
TableId = i
};
if (isMapping)
{
columnInfo.DbColumnName = GetDbColumnName(column.PropertyName);
}
if (column.IsJson)
{
columnInfo.IsJson = true;
@ -645,8 +650,8 @@ namespace SqlSugar
if(columnInfo.Value!=null)
columnInfo.Value = this.Context.Utilities.SerializeObject(columnInfo.Value);
}
var tranColumn=EntityInfo.Columns.FirstOrDefault(it => it.IsTranscoding && it.DbColumnName.Equals(column.DbColumnName, StringComparison.CurrentCultureIgnoreCase));
if (tranColumn!=null&&columnInfo.Value.HasValue()) {
//var tranColumn=EntityInfo.Columns.FirstOrDefault(it => it.IsTranscoding && it.DbColumnName.Equals(column.DbColumnName, StringComparison.CurrentCultureIgnoreCase));
if (column.IsTranscoding&&columnInfo.Value.HasValue()) {
columnInfo.Value = UtilMethods.EncodeBase64(columnInfo.Value.ToString());
}
insertItem.Add(columnInfo);

26
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Realization/SqlServer/SqlBuilder/SqlServerBlukCopy.cs

@ -123,28 +123,20 @@ namespace SqlSugar
foreach (var rowInfos in DbColumnInfoList)
{
var dr = dt.NewRow();
foreach (DataColumn item in dt.Columns)
foreach (var value in rowInfos)
{
var rows = rowInfos.ToList();
var value = rows.FirstOrDefault(it =>
it.DbColumnName.Equals(item.ColumnName, StringComparison.CurrentCultureIgnoreCase) ||
it.PropertyName.Equals(item.ColumnName, StringComparison.CurrentCultureIgnoreCase)
);
if (value != null)
if (value.Value != null && UtilMethods.GetUnderType(value.Value.GetType()) == UtilConstants.DateType)
{
if (value.Value != null && UtilMethods.GetUnderType(value.Value.GetType()) == UtilConstants.DateType)
if (value.Value != null && value.Value.ToString() == DateTime.MinValue.ToString())
{
if (value.Value != null && value.Value.ToString() == DateTime.MinValue.ToString())
{
value.Value = Convert.ToDateTime("1753/01/01");
}
value.Value = Convert.ToDateTime("1753/01/01");
}
if (value.Value == null)
{
value.Value = DBNull.Value;
}
dr[item.ColumnName] = value.Value;
}
if (value.Value == null)
{
value.Value = DBNull.Value;
}
dr[value.DbColumnName] = value.Value;
}
dt.Rows.Add(dr);
}

69
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/PropertyCallAdapterProvider.cs

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace SqlSugar
{
public interface IPropertyCallAdapter<TThis>
{
object InvokeGet(TThis @this);
//add void InvokeSet(TThis @this, object value) if necessary
}
public class PropertyCallAdapter<TThis, TResult> : IPropertyCallAdapter<TThis>
{
private readonly Func<TThis, TResult> _getterInvocation;
public PropertyCallAdapter(Func<TThis, TResult> getterInvocation)
{
_getterInvocation = getterInvocation;
}
public object InvokeGet(TThis @this)
{
return _getterInvocation.Invoke(@this);
}
}
public class PropertyCallAdapterProvider<TThis>
{
private static readonly Dictionary<string, IPropertyCallAdapter<TThis>> _instances =
new Dictionary<string, IPropertyCallAdapter<TThis>>();
public static IPropertyCallAdapter<TThis> GetInstance(string forPropertyName)
{
IPropertyCallAdapter<TThis> instance;
if (!_instances.TryGetValue(forPropertyName, out instance))
{
var property = typeof(TThis).GetProperty(
forPropertyName,
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
MethodInfo getMethod;
Delegate getterInvocation = null;
if (property != null && (getMethod = property.GetGetMethod(true)) != null)
{
var openGetterType = typeof(Func<,>);
var concreteGetterType = openGetterType
.MakeGenericType(typeof(TThis), property.PropertyType);
getterInvocation =
Delegate.CreateDelegate(concreteGetterType, null, getMethod);
}
else
{
//throw exception or create a default getterInvocation returning null
}
var openAdapterType = typeof(PropertyCallAdapter<,>);
var concreteAdapterType = openAdapterType
.MakeGenericType(typeof(TThis), property.PropertyType);
instance = Activator
.CreateInstance(concreteAdapterType, getterInvocation)
as IPropertyCallAdapter<TThis>;
_instances.Add(forPropertyName, instance);
}
return instance;
}
}
}
Loading…
Cancel
Save