Synchronization code

This commit is contained in:
sunkaixuan 2023-09-13 12:13:09 +08:00
parent 5cf8839b80
commit 5a241248b1
2 changed files with 23 additions and 1 deletions

View File

@ -717,7 +717,9 @@ namespace SqlSugar
}
if (appendColumnsByDataFilter)
{
var data = ((UpdateableProvider<T>)this.Context.Updateable(new T() { })).UpdateObjs.First();
var newData = new T() { };
UtilMethods.ClearPublicProperties(newData, this.EntityInfo);
var data = ((UpdateableProvider<T>)this.Context.Updateable(newData)).UpdateObjs.First();
foreach (var item in this.EntityInfo.Columns.Where(it => !it.IsPrimarykey && !it.IsIgnore && !it.IsOnlyIgnoreUpdate))
{
var value = item.PropertyInfo.GetValue(data);

View File

@ -18,6 +18,26 @@ namespace SqlSugar
{
public class UtilMethods
{
public static void ClearPublicProperties<T>(T obj,EntityInfo entity)
{
if (obj == null)
{
throw new ArgumentNullException(nameof(obj));
}
Type type = typeof(T);
foreach (var column in entity.Columns)
{
if (column.PropertyInfo.CanWrite && column.PropertyInfo.GetSetMethod() != null)
{
Type propertyType = column.PropertyInfo.PropertyType;
object defaultValue = propertyType.IsValueType ? Activator.CreateInstance(propertyType) : null;
column.PropertyInfo.SetValue(obj, defaultValue);
}
}
}
internal static Expression GetIncludeExpression(string navMemberName, EntityInfo entityInfo, out Type properyItemType,out bool isList)
{
var navInfo = entityInfo.Columns.Where(it => it.Navigat != null && it.PropertyName.EqualCase(navMemberName)).FirstOrDefault();