diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/DynamicProperyBuilder.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/DynamicProperyBuilder.cs index 18cba77c5..516e18b4c 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/DynamicProperyBuilder.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/DynamicProperyBuilder.cs @@ -18,13 +18,24 @@ namespace SqlSugar return new DynamicProperyBuilder(); } public DynamicBuilder baseBuilder; - public DynamicProperyBuilder CreateProperty(string propertyName, Type properyType, SugarColumn table) + public DynamicProperyBuilder CreateProperty(string propertyName, Type properyType, SugarColumn column=null,bool isSplitField=false) { + if (column == null) + { + column = new SugarColumn() + { + ColumnName=propertyName + }; + } PropertyMetadata addItem = new PropertyMetadata(); addItem.Name = propertyName; addItem.Type = properyType; - addItem.CustomAttributes = new List() { baseBuilder.GetProperty(table) }; + addItem.CustomAttributes = new List() { baseBuilder.GetProperty(column) }; baseBuilder.propertyAttr.Add(addItem); + if (isSplitField) + { + addItem.CustomAttributes.Add(baseBuilder.GetSplitFieldAttr(new SplitFieldAttribute())); + } return this; } public DynamicProperyBuilder WithCache(bool isCache=true) diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Helper.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Helper.cs index e40dcca61..eef70f68a 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Helper.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Helper.cs @@ -10,6 +10,26 @@ namespace SqlSugar { public partial class DynamicBuilder { + internal CustomAttributeBuilder GetSplitEntityAttr(SplitTableAttribute sugarTable) + { + Type attributeType = typeof(SplitTableAttribute); + ConstructorInfo attributeCtor = attributeType.GetConstructor(new Type[] { typeof(SplitType) }); + CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(attributeCtor, new object[] { sugarTable.SplitType }, + new PropertyInfo[] { + attributeType.GetProperty(nameof(SplitTableAttribute.SplitType)), + } + , new object[] { + sugarTable.SplitType + }); + return attributeBuilder; + } + internal CustomAttributeBuilder GetSplitFieldAttr(SplitFieldAttribute fieldAttribute) + { + Type attributeType = typeof(SplitFieldAttribute); + ConstructorInfo attributeCtor = attributeType.GetConstructor(new Type[] { }); + CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(attributeCtor, new object[] { }); + return attributeBuilder; + } internal CustomAttributeBuilder GetEntity(SugarTable sugarTable) { Type attributeType = typeof(SugarTable); diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Master.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Master.cs index 81be775b4..301078a69 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Master.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/DynamicBuilder/Master.cs @@ -23,12 +23,20 @@ namespace SqlSugar this.context = context; } - public DynamicProperyBuilder CreateClass(string entityName, SugarTable table, Type baseType = null, Type[] interfaces = null) + public DynamicProperyBuilder CreateClass(string entityName, SugarTable table=null, Type baseType = null, Type[] interfaces = null,SplitTableAttribute splitTableAttribute=null) { this.baseType = baseType; this.interfaces = interfaces; this.entityName = entityName; + if (table == null) + { + table = new SugarTable() { TableName = entityName }; + } this.entityAttr = new List() { GetEntity(table) }; + if (splitTableAttribute != null) + { + this.entityAttr.Add(GetSplitEntityAttr(splitTableAttribute)); + } return new DynamicProperyBuilder() { baseBuilder=this}; } diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/PropertyMetadata.cs b/Src/Asp.NetCore2/SqlSugar/Entities/PropertyMetadata.cs index 530e99a53..12a5c342d 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/PropertyMetadata.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/PropertyMetadata.cs @@ -11,6 +11,6 @@ namespace SqlSugar { public string Name { get; set; } public Type Type { get; set; } - public IEnumerable CustomAttributes { get; set; } + public List CustomAttributes { get; set; } } }