mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-17 05:29:33 +08:00
Synchronization code
This commit is contained in:
parent
5f9ff95de1
commit
5a2a22ed59
@ -323,6 +323,10 @@ namespace SqlSugar
|
||||
column.PropertyName = property.Name;
|
||||
column.PropertyInfo = property;
|
||||
column.UnderType = UtilMethods.GetUnderType(column.PropertyInfo.PropertyType);
|
||||
if (sugarColumn?.IsOwnsOne==true)
|
||||
{
|
||||
SetValueObjectColumns(result, property, column);
|
||||
}
|
||||
if (sugarColumn.IsNullOrEmpty())
|
||||
{
|
||||
column.DbColumnName = property.Name;
|
||||
@ -448,6 +452,24 @@ namespace SqlSugar
|
||||
result.Columns.Add(column);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetValueObjectColumns(EntityInfo result, PropertyInfo property, EntityColumnInfo column)
|
||||
{
|
||||
column.IsIgnore = true;
|
||||
column.IsOwnsOne = true;
|
||||
Check.ExceptionEasy(property.PropertyType.IsClass() == false, column.PropertyName + " IsOwnsOne必须用在类上面", column.PropertyName + "IsOwnsOne must be used on the class");
|
||||
Check.ExceptionEasy(property.PropertyType.FullName.IsCollectionsList() == true, column.PropertyName + " IsOwnsOne必须用在类上面", column.PropertyName + "IsOwnsOne must be used on the class");
|
||||
var ownsOne = this.GetEntityInfoNoCache(property.PropertyType);
|
||||
foreach (var item in ownsOne.Columns)
|
||||
{
|
||||
if (result.Columns.Any(it => it.PropertyName.EqualCase(item.PropertyName) || it.DbColumnName.EqualCase(item.DbColumnName)))
|
||||
{
|
||||
Check.ExceptionEasy($" {result.EntityName} "+ item.PropertyName+ " 存在重复定义 (IsOwnsOne) ", $" {result.EntityName} " + item.PropertyName + " Duplicate definition exists (IsOwnsOne)");
|
||||
}
|
||||
item.ForOwnsOnePropertyInfo = column.PropertyInfo;
|
||||
result.Columns.Add(item);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -318,6 +318,11 @@ namespace SqlSugar
|
||||
}
|
||||
private static object GetValue(T item, EntityColumnInfo column)
|
||||
{
|
||||
if (column.ForOwnsOnePropertyInfo != null)
|
||||
{
|
||||
var owsPropertyValue= column.ForOwnsOnePropertyInfo.GetValue(item, null);
|
||||
return column.PropertyInfo.GetValue(owsPropertyValue, null);
|
||||
}
|
||||
if (StaticConfig.EnableAot)
|
||||
{
|
||||
return column.PropertyInfo.GetValue(item, null);
|
||||
|
@ -328,14 +328,14 @@ namespace SqlSugar
|
||||
Check.ExceptionEasy(item == null, "db.Updateable(data) data is required ", "db.Updateable(data) data不能是null");
|
||||
var columnInfo = new DbColumnInfo()
|
||||
{
|
||||
Value = column.PropertyInfo.GetValue(item, null),
|
||||
Value = GetValue(item, column),
|
||||
DbColumnName = GetDbColumnName(column.PropertyName),
|
||||
PropertyName = column.PropertyName,
|
||||
PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
|
||||
SqlParameterDbType = column.SqlParameterDbType,
|
||||
TableId = i,
|
||||
UpdateSql=column.UpdateSql,
|
||||
UpdateServerTime= column.UpdateServerTime
|
||||
UpdateSql = column.UpdateSql,
|
||||
UpdateServerTime = column.UpdateServerTime
|
||||
};
|
||||
if (columnInfo.PropertyType.IsEnum() && columnInfo.Value != null)
|
||||
{
|
||||
@ -369,6 +369,19 @@ namespace SqlSugar
|
||||
this.UpdateBuilder.DbColumnInfoList.AddRange(updateItem);
|
||||
}
|
||||
|
||||
private static object GetValue(T item, EntityColumnInfo column)
|
||||
{
|
||||
if (column.ForOwnsOnePropertyInfo != null)
|
||||
{
|
||||
var owsPropertyValue = column.ForOwnsOnePropertyInfo.GetValue(item, null);
|
||||
return column.PropertyInfo.GetValue(owsPropertyValue, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
return column.PropertyInfo.GetValue(item, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void PreToSql()
|
||||
{
|
||||
if (this.UpdateBuilder.UpdateColumns.HasValue())
|
||||
|
@ -48,5 +48,7 @@ namespace SqlSugar
|
||||
public object ExtendedAttribute { get; set; }
|
||||
public bool IsDisabledAlterColumn { get; set; }
|
||||
public string QuerySql { get; set; }
|
||||
public bool IsOwnsOne { get; set; }
|
||||
public PropertyInfo ForOwnsOnePropertyInfo { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -215,6 +215,7 @@ namespace SqlSugar
|
||||
public string UpdateSql { get; set; }
|
||||
public object ExtendedAttribute{ get; set; }
|
||||
public bool IsDisabledAlterColumn { get; set; }
|
||||
public bool IsOwnsOne { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user