mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 12:47:57 +08:00
Synchronization code
This commit is contained in:
parent
31b4922411
commit
73c8e025a0
@ -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<CustomAttributeBuilder>() { baseBuilder.GetProperty(table) };
|
||||
addItem.CustomAttributes = new List<CustomAttributeBuilder>() { baseBuilder.GetProperty(column) };
|
||||
baseBuilder.propertyAttr.Add(addItem);
|
||||
if (isSplitField)
|
||||
{
|
||||
addItem.CustomAttributes.Add(baseBuilder.GetSplitFieldAttr(new SplitFieldAttribute()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public DynamicProperyBuilder WithCache(bool isCache=true)
|
||||
|
@ -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);
|
||||
|
@ -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<CustomAttributeBuilder>() { GetEntity(table) };
|
||||
if (splitTableAttribute != null)
|
||||
{
|
||||
this.entityAttr.Add(GetSplitEntityAttr(splitTableAttribute));
|
||||
}
|
||||
return new DynamicProperyBuilder() { baseBuilder=this};
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,6 @@ namespace SqlSugar
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Type Type { get; set; }
|
||||
public IEnumerable<CustomAttributeBuilder> CustomAttributes { get; set; }
|
||||
public List<CustomAttributeBuilder> CustomAttributes { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user