@@ -34,12 +34,7 @@ private static EntityInfo GetEntityInfo<T>(DbContext dbContext)
3434 . GetProperties ( )
3535 . Select ( x =>
3636 {
37- #if NET7_0_OR_GREATER
3837 var name = x . GetColumnName ( ) ;
39- #else
40- var storeObjectIdentifier = StoreObjectIdentifier . Table ( tableName , schema ) ;
41- var name = x . GetColumnName ( storeObjectIdentifier ) ;
42- #endif
4338 var refName = x . Name ;
4439 var isIdentity = x . ValueGenerated == ValueGenerated . OnAddOrUpdate ;
4540 var skipInsert = x . ValueGenerated == ValueGenerated . OnAddOrUpdate ;
@@ -48,7 +43,7 @@ private static EntityInfo GetEntityInfo<T>(DbContext dbContext)
4843 var isPrimaryKey = x . IsPrimaryKey ( ) ;
4944 var isKey = x . IsKey ( ) ;
5045
51- return new ColumnInfo ( name ! , refName , isPrimaryKey , isUniqueIndex , isKey , isIdentity , skipInsert ,
46+ return new ColumnInfo ( name , refName , isPrimaryKey , isUniqueIndex , isKey , isIdentity , skipInsert ,
5247 skipUpdate )
5348 {
5449 ValueConverter = x . GetValueConverter ( )
@@ -64,9 +59,9 @@ private static EntityInfo GetEntityInfo<T>(DbContext dbContext)
6459 /// </summary>
6560 private static string [ ] GetExpressionFields < T > ( Expression < Func < T , object > > ? expression )
6661 {
67- if ( expression is null ) return Array . Empty < string > ( ) ;
62+ if ( expression is null ) return [ ] ;
6863 var instance = JsonSerializer . Deserialize < T > ( "{}" ) ;
69- if ( instance is null ) return Array . Empty < string > ( ) ;
64+ if ( instance is null ) return [ ] ;
7065
7166 var expr = expression . Compile ( ) ;
7267 var anonymousInstance = expr . Invoke ( instance ) ;
@@ -87,10 +82,10 @@ internal static List<BatchData> GenerateInsertBatches<T>(DbContext dbContext, IR
8782 BulkOption < T > ? option )
8883 where T : class
8984 {
90- if ( items . Count == 0 ) return new List < BatchData > ( ) ;
85+ if ( items . Count == 0 ) return [ ] ;
9186
9287 var info = GetEntityInfo < T > ( dbContext ) ;
93- string [ ] ignoreFields = Array . Empty < string > ( ) ;
88+ string [ ] ignoreFields = [ ] ;
9489 if ( option ? . IgnoreOnInsert is not null ) ignoreFields = GetExpressionFields ( option . IgnoreOnInsert ) ;
9590
9691 var columns = info . Columns
@@ -106,7 +101,7 @@ internal static List<BatchData> GenerateInsertBatches<T>(DbContext dbContext, IR
106101 . Select ( rows =>
107102 {
108103 var tmpTable = ToTempTable ( columns , rows , offset ) ;
109- if ( tmpTable is null ) return new BatchData ( new StringBuilder ( ) , new List < SqlParameter > ( ) ) ;
104+ if ( tmpTable is null ) return new BatchData ( new StringBuilder ( ) , [ ] ) ;
110105
111106 tmpTable . Sql . Insert ( 0 ,
112107 @$ "INSERT INTO `{ info . TableName } `
@@ -134,10 +129,10 @@ internal static List<BatchData> GenerateUpdateBatches<T>(DbContext dbContext, IR
134129 BulkOption < T > ? option )
135130 where T : class
136131 {
137- if ( items . Count == 0 ) return new List < BatchData > ( ) ;
132+ if ( items . Count == 0 ) return [ ] ;
138133 var info = GetEntityInfo < T > ( dbContext ) ;
139134
140- string [ ] ignoreFields = Array . Empty < string > ( ) ;
135+ string [ ] ignoreFields = [ ] ;
141136 if ( option ? . IgnoreOnUpdate is not null ) ignoreFields = GetExpressionFields ( option . IgnoreOnUpdate ) ;
142137
143138 var columns = info . Columns
@@ -153,16 +148,31 @@ internal static List<BatchData> GenerateUpdateBatches<T>(DbContext dbContext, IR
153148 . Select ( rows =>
154149 {
155150 var tmpTable = ToTempTable ( columns , rows , offset ) ;
156- if ( tmpTable is null ) return new BatchData ( new StringBuilder ( ) , new List < SqlParameter > ( ) ) ;
151+ if ( tmpTable is null ) return new BatchData ( new StringBuilder ( ) , [ ] ) ;
157152
158153 tmpTable . Sql . Insert ( 0 ,
159154 @$ "UPDATE `{ info . TableName } ` AS tb
160155INNER JOIN " ) ;
161156
162- // Auto detects unique keys or specific custom unique keys
163- var keys = option ? . UniqueKeys is not null
164- ? GetExpressionFields ( option . UniqueKeys )
165- : columns . Where ( x => x . IsUniqueIndex ) . Select ( x => x . Name ) ;
157+ List < string > keys ;
158+ if ( option ? . UniqueKeys is not null )
159+ {
160+ // Specific custom unique keys
161+ var uniqueKeys = GetExpressionFields ( option . UniqueKeys ) ;
162+ keys = columns
163+ . Where ( x => uniqueKeys . Contains ( x . RefName ) )
164+ . Select ( x => x . Name )
165+ . ToList ( ) ;
166+ }
167+ else
168+ {
169+ // Auto detects unique keys
170+ keys = columns
171+ . Where ( x => x . IsUniqueIndex )
172+ . Select ( x => x . Name )
173+ . ToList ( ) ;
174+ }
175+
166176 keys
167177 . ForEachWithIndex ( ( key , index ) =>
168178 {
@@ -199,7 +209,7 @@ internal static List<BatchData> GenerateDeleteBatches<T>(DbContext dbContext, IR
199209 BulkOption < T > ? option )
200210 where T : class
201211 {
202- if ( items . Count == 0 ) return new List < BatchData > ( ) ;
212+ if ( items . Count == 0 ) return [ ] ;
203213 var info = GetEntityInfo < T > ( dbContext ) ;
204214
205215 List < ColumnInfo > columns ;
@@ -213,9 +223,9 @@ internal static List<BatchData> GenerateDeleteBatches<T>(DbContext dbContext, IR
213223 else
214224 {
215225 // Specific custom unique keys
216- var keys = GetExpressionFields ( option . UniqueKeys ) ;
226+ var uniqueKeys = GetExpressionFields ( option . UniqueKeys ) ;
217227 columns = info . Columns
218- . Where ( x => keys . Contains ( x . Name ) )
228+ . Where ( x => uniqueKeys . Contains ( x . RefName ) )
219229 . ToList ( ) ;
220230 }
221231
@@ -228,7 +238,7 @@ internal static List<BatchData> GenerateDeleteBatches<T>(DbContext dbContext, IR
228238 . Select ( rows =>
229239 {
230240 var tmpTable = ToTempTable ( columns , rows , offset ) ;
231- if ( tmpTable is null ) return new BatchData ( new StringBuilder ( ) , new List < SqlParameter > ( ) ) ;
241+ if ( tmpTable is null ) return new BatchData ( new StringBuilder ( ) , [ ] ) ;
232242
233243 tmpTable . Sql . Insert ( 0 ,
234244 @$ "DELETE tb
@@ -262,18 +272,18 @@ internal static List<BatchData> GenerateMergeBatches<T>(DbContext dbContext,
262272 BulkOption < T > ? option )
263273 where T : class
264274 {
265- if ( items . Count == 0 ) return new List < BatchData > ( ) ;
275+ if ( items . Count == 0 ) return [ ] ;
266276
267277 var info = GetEntityInfo < T > ( dbContext ) ;
268- string [ ] ignoreInsertFields = Array . Empty < string > ( ) ;
278+ string [ ] ignoreInsertFields = [ ] ;
269279 if ( option ? . IgnoreOnInsert is not null ) ignoreInsertFields = GetExpressionFields ( option . IgnoreOnInsert ) ;
270280 var insertCols = info . Columns
271281 . Where ( x => x is { SkipInsert : false }
272282 && ! ignoreInsertFields . Contains ( x . RefName )
273283 )
274284 . ToList ( ) ;
275285
276- string [ ] ignoreUpdateFields = Array . Empty < string > ( ) ;
286+ string [ ] ignoreUpdateFields = [ ] ;
277287 if ( option ? . IgnoreOnUpdate is not null ) ignoreUpdateFields = GetExpressionFields ( option . IgnoreOnUpdate ) ;
278288 var updateCols = info . Columns
279289 . Where ( x => x is { IsPrimaryKey : false , IsUniqueIndex : false , SkipUpdate : false }
@@ -293,7 +303,7 @@ internal static List<BatchData> GenerateMergeBatches<T>(DbContext dbContext,
293303 . Select ( rows =>
294304 {
295305 var tmpTable = ToTempTable ( combineColumns , rows , offset ) ;
296- if ( tmpTable is null ) return new BatchData ( new StringBuilder ( ) , new List < SqlParameter > ( ) ) ;
306+ if ( tmpTable is null ) return new BatchData ( new StringBuilder ( ) , [ ] ) ;
297307
298308 tmpTable . Sql . Insert ( 0 ,
299309 @$ "INSERT INTO `{ info . TableName } `
@@ -330,13 +340,13 @@ internal static List<BatchData> GenerateMergeBatches<T>(DbContext dbContext,
330340 where T : class
331341 {
332342 if ( rows . Count == 0 ) return null ;
333- List < SqlParameter > parameters = new List < SqlParameter > ( ) ;
343+ List < SqlParameter > parameters = [ ] ;
334344 var sql = new StringBuilder ( "(" ) ;
335345 sql . AppendLine ( ) ;
336346 rows . ForEachWithIndex ( ( row , rowIndex ) =>
337347 {
338348 sql . Append ( rowIndex == 0 ? "SELECT " : "UNION ALL SELECT " ) ;
339- List < SqlParameter > list = new List < SqlParameter > ( ) ;
349+ List < SqlParameter > list = [ ] ;
340350 var type = row . GetType ( ) ;
341351 var colIndex = 0 ;
342352 columns . ToList ( ) . ForEach ( column =>
0 commit comments