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) foreach (var column in EntityInfo.Columns)
{ {
if (column.IsIgnore || column.IsOnlyIgnoreInsert) continue; if (column.IsIgnore || column.IsOnlyIgnoreInsert) continue;
var isMapping = IsMappingColumns;
var columnInfo = new DbColumnInfo() var columnInfo = new DbColumnInfo()
{ {
Value = column.PropertyInfo.GetValue(item, null), Value = PropertyCallAdapterProvider<T>.GetInstance(column.PropertyName).InvokeGet(item),
DbColumnName = GetDbColumnName(column.PropertyName), DbColumnName = column.DbColumnName,
PropertyName = column.PropertyName, PropertyName = column.PropertyName,
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo), PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
TableId = i TableId = i
}; };
if (isMapping)
{
columnInfo.DbColumnName = GetDbColumnName(column.PropertyName);
}
if (column.IsJson) if (column.IsJson)
{ {
columnInfo.IsJson = true; columnInfo.IsJson = true;
@ -645,8 +650,8 @@ namespace SqlSugar
if(columnInfo.Value!=null) if(columnInfo.Value!=null)
columnInfo.Value = this.Context.Utilities.SerializeObject(columnInfo.Value); columnInfo.Value = this.Context.Utilities.SerializeObject(columnInfo.Value);
} }
var tranColumn=EntityInfo.Columns.FirstOrDefault(it => it.IsTranscoding && it.DbColumnName.Equals(column.DbColumnName, StringComparison.CurrentCultureIgnoreCase)); //var tranColumn=EntityInfo.Columns.FirstOrDefault(it => it.IsTranscoding && it.DbColumnName.Equals(column.DbColumnName, StringComparison.CurrentCultureIgnoreCase));
if (tranColumn!=null&&columnInfo.Value.HasValue()) { if (column.IsTranscoding&&columnInfo.Value.HasValue()) {
columnInfo.Value = UtilMethods.EncodeBase64(columnInfo.Value.ToString()); columnInfo.Value = UtilMethods.EncodeBase64(columnInfo.Value.ToString());
} }
insertItem.Add(columnInfo); 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) foreach (var rowInfos in DbColumnInfoList)
{ {
var dr = dt.NewRow(); var dr = dt.NewRow();
foreach (DataColumn item in dt.Columns) foreach (var value in rowInfos)
{ {
var rows = rowInfos.ToList(); if (value.Value != null && UtilMethods.GetUnderType(value.Value.GetType()) == UtilConstants.DateType)
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 && 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); 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