@@ -16,13 +16,16 @@ namespace ShardingCore.Core.EntityMetadatas
1616 /// 分表或者分库对象的元数据信息记录对象在ShardingCore框架下的一些简单的信息
1717 /// </summary>
1818 public class EntityMetadata
19- { private const string QueryFilter = "QueryFilter" ;
19+ {
20+ private const string QueryFilter = "QueryFilter" ;
21+
2022 public EntityMetadata ( Type entityType )
2123 {
2224 EntityType = entityType ;
2325 ShardingDataSourceProperties = new Dictionary < string , PropertyInfo > ( ) ;
2426 ShardingTableProperties = new Dictionary < string , PropertyInfo > ( ) ;
2527 }
28+
2629 /// <summary>
2730 /// 分表类型 sharding entity type
2831 /// </summary>
@@ -37,10 +40,12 @@ public EntityMetadata(Type entityType)
3740 /// 是否分表
3841 /// </summary>
3942 public bool IsMultiTableMapping => null != ShardingTableProperty ;
43+
4044 /// <summary>
4145 /// 分库字段
4246 /// </summary>
4347 public PropertyInfo ShardingDataSourceProperty { get ; private set ; }
48+
4449 /// <summary>
4550 /// 分库所有字段包括 ShardingDataSourceProperty
4651 /// </summary>
@@ -49,37 +54,39 @@ public EntityMetadata(Type entityType)
4954 /// <summary>
5055 /// 启动时是否建表 auto create data source when start app
5156 /// </summary>
52- public bool ? AutoCreateDataSourceTable { get ; set ; }
57+ public bool ? AutoCreateDataSourceTable { get ; set ; }
5358
5459 /// <summary>
5560 /// 分表字段 sharding table property
5661 /// </summary>
5762 public PropertyInfo ShardingTableProperty { get ; private set ; }
63+
5864 /// <summary>
5965 /// 分表所有字段包括 ShardingTableProperty
6066 /// </summary>
61- public IDictionary < string , PropertyInfo > ShardingTableProperties { get ; }
67+ public IDictionary < string , PropertyInfo > ShardingTableProperties { get ; }
6268
6369
6470 /// <summary>
6571 /// 启动时是否建表 auto create table when start app
6672 /// </summary>
67- public bool ? AutoCreateTable { get ; set ; }
73+ public bool ? AutoCreateTable { get ; set ; }
6874
6975 /// <summary>
7076 /// 分表隔离器 table sharding tail prefix
7177 /// </summary>
7278 public string TableSeparator { get ; private set ; } = "_" ;
73-
79+
7480 /// <summary>
7581 /// 逻辑表名
7682 /// </summary>
7783 public string LogicTableName { get ; private set ; }
78-
84+
7985 /// <summary>
8086 /// 主键
8187 /// </summary>
8288 public IReadOnlyList < PropertyInfo > PrimaryKeyProperties { get ; private set ; }
89+
8390 /**
8491 * efcore query filter
8592 */
@@ -93,14 +100,14 @@ public EntityMetadata(Type entityType)
93100 public void SetEntityModel ( IEntityType dbEntityType )
94101 {
95102 LogicTableName = dbEntityType . GetEntityTypeTableName ( ) ;
96- QueryFilterExpression = dbEntityType . GetAnnotations ( ) . FirstOrDefault ( o=> o . Name == QueryFilter ) ? . Value as LambdaExpression ;
103+ QueryFilterExpression =
104+ dbEntityType . GetAnnotations ( ) . FirstOrDefault ( o => o . Name == QueryFilter ) ? . Value as LambdaExpression ;
97105 PrimaryKeyProperties = dbEntityType . FindPrimaryKey ( ) ? . Properties ? . Select ( o => o . PropertyInfo ) ? . ToList ( ) ??
98106 new List < PropertyInfo > ( ) ;
99- IsSingleKey = PrimaryKeyProperties . Count == 1 ;
107+ IsSingleKey = PrimaryKeyProperties . Count == 1 ;
100108 }
101-
102-
103-
109+
110+
104111 /// <summary>
105112 /// 设置分库字段
106113 /// </summary>
@@ -109,10 +116,12 @@ public void SetShardingDataSourceProperty(PropertyInfo propertyInfo)
109116 {
110117 Check . NotNull ( propertyInfo , nameof ( propertyInfo ) ) ;
111118 if ( ShardingDataSourceProperties . ContainsKey ( propertyInfo . Name ) )
112- throw new ShardingCoreConfigException ( $ "same sharding data source property name:[{ propertyInfo . Name } ] don't repeat add") ;
119+ throw new ShardingCoreConfigException (
120+ $ "same sharding data source property name:[{ propertyInfo . Name } ] don't repeat add") ;
113121 ShardingDataSourceProperty = propertyInfo ;
114122 ShardingDataSourceProperties . Add ( propertyInfo . Name , propertyInfo ) ;
115123 }
124+
116125 /// <summary>
117126 /// 添加额外分表字段
118127 /// </summary>
@@ -121,9 +130,11 @@ public void SetShardingDataSourceProperty(PropertyInfo propertyInfo)
121130 public void AddExtraSharingDataSourceProperty ( PropertyInfo propertyInfo )
122131 {
123132 if ( ShardingDataSourceProperties . ContainsKey ( propertyInfo . Name ) )
124- throw new ShardingCoreConfigException ( $ "same sharding data source property name:[{ propertyInfo . Name } ] don't repeat add") ;
133+ throw new ShardingCoreConfigException (
134+ $ "same sharding data source property name:[{ propertyInfo . Name } ] don't repeat add") ;
125135 ShardingDataSourceProperties . Add ( propertyInfo . Name , propertyInfo ) ;
126136 }
137+
127138 /// <summary>
128139 /// 设置分表字段
129140 /// </summary>
@@ -132,10 +143,12 @@ public void SetShardingTableProperty(PropertyInfo propertyInfo)
132143 {
133144 Check . NotNull ( propertyInfo , nameof ( propertyInfo ) ) ;
134145 if ( ShardingTableProperties . ContainsKey ( propertyInfo . Name ) )
135- throw new ShardingCoreConfigException ( $ "same sharding table property name:[{ propertyInfo . Name } ] don't repeat add") ;
146+ throw new ShardingCoreConfigException (
147+ $ "same sharding table property name:[{ propertyInfo . Name } ] don't repeat add") ;
136148 ShardingTableProperty = propertyInfo ;
137149 ShardingTableProperties . Add ( propertyInfo . Name , propertyInfo ) ;
138150 }
151+
139152 /// <summary>
140153 /// 添加额外分表字段
141154 /// </summary>
@@ -144,7 +157,8 @@ public void SetShardingTableProperty(PropertyInfo propertyInfo)
144157 public void AddExtraSharingTableProperty ( PropertyInfo propertyInfo )
145158 {
146159 if ( ShardingTableProperties . ContainsKey ( propertyInfo . Name ) )
147- throw new ShardingCoreConfigException ( $ "same sharding table property name:[{ propertyInfo . Name } ] don't repeat add") ;
160+ throw new ShardingCoreConfigException (
161+ $ "same sharding table property name:[{ propertyInfo . Name } ] don't repeat add") ;
148162 ShardingTableProperties . Add ( propertyInfo . Name , propertyInfo ) ;
149163 }
150164
@@ -156,6 +170,7 @@ public void SetTableSeparator(string separator)
156170 {
157171 TableSeparator = separator ;
158172 }
173+
159174 /// <summary>
160175 /// 启动时检查分库信息是否完整
161176 /// </summary>
@@ -165,11 +180,13 @@ public void CheckShardingDataSourceMetadata()
165180 {
166181 throw new ShardingCoreException ( $ "not found entity:{ EntityType } configure") ;
167182 }
168- if ( ShardingDataSourceProperty == null )
183+
184+ if ( ShardingDataSourceProperty == null )
169185 {
170186 throw new ShardingCoreException ( $ "not found entity:{ EntityType } configure sharding property") ;
171187 }
172188 }
189+
173190 /// <summary>
174191 /// 启动时检查分表信息是否完整
175192 /// </summary>
@@ -179,11 +196,13 @@ public void CheckShardingTableMetadata()
179196 {
180197 throw new ShardingCoreException ( $ "not found entity:{ EntityType } configure") ;
181198 }
199+
182200 if ( ShardingTableProperty == null )
183201 {
184202 throw new ShardingCoreException ( $ "not found entity:{ EntityType } configure sharding property") ;
185203 }
186204 }
205+
187206 /// <summary>
188207 /// 启动时检查对象信息是否完整
189208 /// </summary>
@@ -195,6 +214,7 @@ public void CheckGenericMetadata()
195214 throw new ShardingCoreException ( $ "not found entity:{ EntityType } configure") ;
196215 }
197216 }
217+
198218 protected bool Equals ( EntityMetadata other )
199219 {
200220 return Equals ( EntityType , other . EntityType ) ;
@@ -213,4 +233,4 @@ public override int GetHashCode()
213233 return ( EntityType != null ? EntityType . GetHashCode ( ) : 0 ) ;
214234 }
215235 }
216- }
236+ }
0 commit comments