File tree 1 file changed +12
-2
lines changed
Interfaces/Cosmos.DataTransfer.Interfaces
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -18,15 +18,25 @@ public static class DataItemExtensions
18
18
19
19
var fields = source . GetFieldNames ( ) . ToList ( ) ;
20
20
var item = new ExpandoObject ( ) ;
21
- if ( requireStringId && ! fields . Contains ( "id" , StringComparer . CurrentCultureIgnoreCase ) )
21
+
22
+ /*
23
+ * If the item contains a lowercase id field, we can take it as is.
24
+ * If we have an uppercase Id or ID field, but no lowercase id, we will rename it to id.
25
+ * Then it can be used i.e. as CosmosDB primary key, when `requireStringId` is set to true.
26
+ */
27
+ var containsLowercaseIdField = fields . Contains ( "id" , StringComparer . CurrentCulture ) ;
28
+ var containsAnyIdField = fields . Contains ( "id" , StringComparer . CurrentCultureIgnoreCase ) ;
29
+
30
+ if ( requireStringId && ! containsAnyIdField )
22
31
{
23
32
item . TryAdd ( "id" , Guid . NewGuid ( ) . ToString ( ) ) ;
24
33
}
34
+
25
35
foreach ( string field in fields )
26
36
{
27
37
object ? value = source . GetValue ( field ) ;
28
38
var fieldName = field ;
29
- if ( string . Equals ( field , "id" , StringComparison . CurrentCultureIgnoreCase ) && requireStringId )
39
+ if ( string . Equals ( field , "id" , StringComparison . CurrentCultureIgnoreCase ) && requireStringId && ! containsLowercaseIdField )
30
40
{
31
41
value = value ? . ToString ( ) ;
32
42
fieldName = "id" ;
You can’t perform that action at this time.
0 commit comments