1+ using System . Text . Json ;
12using Microsoft . EntityFrameworkCore ;
23using Microsoft . EntityFrameworkCore . Metadata ;
34using Microsoft . EntityFrameworkCore . Migrations ;
@@ -180,6 +181,8 @@ HashSet<IndexDescriptor> results
180181
181182 var indexName = def . IndexName ?? $ "IX_{ tableName } _{ string . Join ( "_" , columnNames ) } ";
182183
184+ var normalized = NormalizeProviderAnnotations ( def . ProviderAnnotations ) ;
185+
183186 results . Add (
184187 new IndexDescriptor (
185188 tableName ,
@@ -188,12 +191,44 @@ HashSet<IndexDescriptor> results
188191 indexName ,
189192 def . IsUnique ,
190193 def . Filter ,
191- def . ProviderAnnotations ?? [ ]
194+ normalized
192195 )
193196 ) ;
194197 }
195198 }
196199
200+ private static Dictionary < string , object ? > NormalizeProviderAnnotations ( Dictionary < string , object ? > ? annotations )
201+ {
202+ if ( annotations is null ) return [ ] ;
203+
204+ var result = new Dictionary < string , object ? > ( annotations . Count ) ;
205+
206+ foreach ( var ( key , value ) in annotations )
207+ {
208+ result [ key ] = value is JsonElement je
209+ ? NormalizeJsonElement ( je )
210+ : value ;
211+ }
212+
213+ return result ;
214+ }
215+
216+ private static object ? NormalizeJsonElement ( JsonElement je )
217+ {
218+ return je . ValueKind switch
219+ {
220+ JsonValueKind . String => je . GetString ( ) ,
221+ JsonValueKind . True => true ,
222+ JsonValueKind . False => false ,
223+ JsonValueKind . Number => je . TryGetInt64 ( out var l ) ? l : je . GetDouble ( ) ,
224+ JsonValueKind . Null => null ,
225+ JsonValueKind . Array => je . EnumerateArray ( )
226+ . Select ( e => e . ValueKind == JsonValueKind . String ? e . GetString ( ) : e . ToString ( ) )
227+ . ToArray ( ) ,
228+ _ => je . ToString ( )
229+ } ;
230+ }
231+
197232 private static string ? ResolveColumnName ( IEntityType entityType , string dotPath )
198233 {
199234 var parts = dotPath . Split ( '.' ) ;
0 commit comments