mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
Support ValueObject
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
@@ -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; }
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user