mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
Synchronization code
This commit is contained in:
@@ -71,13 +71,29 @@ namespace SqlSugar
|
||||
Type sourceType = typeof(T);
|
||||
Dictionary<string, PropertyInfo> sourceProperties = entity.Columns.Where(it=> propertyNames.Contains(it.PropertyName)).ToDictionary(it=>it.PropertyName,it=>it.PropertyInfo);
|
||||
|
||||
Type dynamicType = LinqRuntimeTypeBuilder.GetDynamicType(sourceProperties.Values);
|
||||
|
||||
ParameterExpression sourceItem = Expression.Parameter(sourceType, "t");
|
||||
IEnumerable<MemberBinding> bindings = dynamicType.GetRuntimeProperties().Select(p => Expression.Bind(p, Expression.Property(sourceItem, sourceProperties[p.Name]))).OfType<MemberBinding>();
|
||||
if (StaticConfig.EnableAot)
|
||||
{
|
||||
Type dynamicType =typeof(T);
|
||||
|
||||
return Expression.Lambda<Func<T, object>>(Expression.MemberInit(
|
||||
Expression.New(dynamicType.GetConstructor(Type.EmptyTypes)), bindings), sourceItem);
|
||||
ParameterExpression sourceItem = Expression.Parameter(sourceType, "t");
|
||||
IEnumerable<MemberBinding> bindings = dynamicType.GetProperties().Where(it=> sourceProperties.Any(s=>s.Key==it.Name)).Select(p => Expression.Bind(p, Expression.Property(sourceItem, sourceProperties[p.Name]))).OfType<MemberBinding>();
|
||||
|
||||
return Expression.Lambda<Func<T, object>>(Expression.MemberInit(
|
||||
Expression.New(dynamicType.GetConstructor(Type.EmptyTypes)), bindings), sourceItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
Type dynamicType = LinqRuntimeTypeBuilder.GetDynamicType(sourceProperties.Values);
|
||||
|
||||
ParameterExpression sourceItem = Expression.Parameter(sourceType, "t");
|
||||
IEnumerable<MemberBinding> bindings = dynamicType.GetRuntimeProperties().Select(p => Expression.Bind(p, Expression.Property(sourceItem, sourceProperties[p.Name]))).OfType<MemberBinding>();
|
||||
|
||||
return Expression.Lambda<Func<T, object>>(Expression.MemberInit(
|
||||
Expression.New(dynamicType.GetConstructor(Type.EmptyTypes)), bindings), sourceItem);
|
||||
}
|
||||
}
|
||||
public static Expression CreateExpressionSelectField(Type classType, string propertyName, Type propertyType)
|
||||
{
|
||||
|
Reference in New Issue
Block a user