BUG: BulkCopy Custom Type

This commit is contained in:
sunkaixuan 2023-09-18 00:30:44 +08:00
parent 01133dbd17
commit e60fcb3673
2 changed files with 20 additions and 1 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
@ -99,7 +100,16 @@ namespace SqlSugar
name = column.PropertyName;
}
var value = ValueConverter(column, PropertyCallAdapterProvider<T>.GetInstance(column.PropertyName).InvokeGet(item));
if (isMySql && column.UnderType == UtilConstants.BoolType)
if (column.SqlParameterDbType != null&& column.SqlParameterDbType is Type && UtilMethods.HasInterface((Type)column.SqlParameterDbType, typeof(ISugarDataConverter)))
{
var columnInfo = column;
var type = columnInfo.SqlParameterDbType as Type;
var ParameterConverter = type.GetMethod("ParameterConverter").MakeGenericMethod(columnInfo.PropertyInfo.PropertyType);
var obj = Activator.CreateInstance(type);
var p = ParameterConverter.Invoke(obj, new object[] { value, 100 }) as SugarParameter;
value = p.Value;
}
else if (isMySql && column.UnderType == UtilConstants.BoolType)
{
if (value.ObjToBool() == false&& uInt64TypeName.Any(z=>z.EqualCase(column.DbColumnName)))

View File

@ -18,6 +18,15 @@ namespace SqlSugar
{
public class UtilMethods
{
public static bool HasInterface(Type targetType, Type interfaceType)
{
if (targetType == null || interfaceType == null || !interfaceType.IsInterface)
{
return false;
}
return interfaceType.IsAssignableFrom(targetType);
}
public static void ClearPublicProperties<T>(T obj,EntityInfo entity)
{
if (obj == null)