Support ValueObject

This commit is contained in:
sunkaixuan
2024-01-30 23:41:15 +08:00
parent 84e257463d
commit 0720661dc5
3 changed files with 23 additions and 0 deletions

View File

@@ -323,6 +323,10 @@ namespace SqlSugar
column.PropertyName = property.Name;
column.PropertyInfo = property;
column.UnderType = UtilMethods.GetUnderType(column.PropertyInfo.PropertyType);
if (sugarColumn.IsOwnsOne)
{
SetValueObjectColumns(result, property, column);
}
if (sugarColumn.IsNullOrEmpty())
{
column.DbColumnName = property.Name;
@@ -448,6 +452,23 @@ 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)");
}
result.Columns.Add(item);
}
}
#endregion
}
}

View File

@@ -48,5 +48,6 @@ namespace SqlSugar
public object ExtendedAttribute { get; set; }
public bool IsDisabledAlterColumn { get; set; }
public string QuerySql { get; set; }
public bool IsOwnsOne { get; set; }
}
}

View File

@@ -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; }
}