44using System . Collections . Generic ;
55using System . Linq . Expressions ;
66using System . Text ;
7+ using System . Text . Json ;
78using Microsoft . Data . SqlClient ;
89using Microsoft . Data . SqlTypes ;
910using Microsoft . Extensions . AI ;
@@ -57,7 +58,15 @@ internal static SqlCommand CreateTable(
5758 {
5859 if ( dataProperty . IsIndexed )
5960 {
60- sb . AppendFormat ( "CREATE INDEX " ) ;
61+ var sqlType = Map ( dataProperty ) ;
62+ if ( sqlType == "JSON" )
63+ {
64+ sb . AppendFormat ( "CREATE JSON INDEX " ) ;
65+ }
66+ else
67+ {
68+ sb . AppendFormat ( "CREATE INDEX " ) ;
69+ }
6170 sb . AppendIndexName ( tableName , dataProperty . StorageName ) ;
6271 sb . AppendFormat ( " ON " ) . AppendTableName ( schema , tableName ) ;
6372 sb . AppendFormat ( "([{0}]);" , dataProperty . StorageName ) ;
@@ -621,6 +630,13 @@ private static void AddParameter(this SqlCommand command, PropertyModel? propert
621630 command . Parameters . AddWithValue ( name , new SqlVector < float > ( vectorArray ) ) ;
622631 break ;
623632
633+ case string [ ] strings :
634+ command . Parameters . AddWithValue ( name , JsonSerializer . Serialize ( strings , SqlServerJsonSerializerContext . Default . StringArray ) ) ;
635+ break ;
636+ case List < string > strings :
637+ command . Parameters . AddWithValue ( name , JsonSerializer . Serialize ( strings , SqlServerJsonSerializerContext . Default . ListString ) ) ;
638+ break ;
639+
624640 default :
625641 command . Parameters . AddWithValue ( name , value ) ;
626642 break ;
@@ -641,6 +657,7 @@ private static string Map(PropertyModel property)
641657 Type t when t == typeof ( byte [ ] ) => "VARBINARY(MAX)" ,
642658 Type t when t == typeof ( bool ) => "BIT" ,
643659 Type t when t == typeof ( DateTime ) => "DATETIME2" ,
660+ Type t when t == typeof ( DateTimeOffset ) => "DATETIMEOFFSET" ,
644661#if NET
645662 Type t when t == typeof ( DateOnly ) => "DATE" ,
646663 Type t when t == typeof ( TimeOnly ) => "TIME" ,
@@ -649,6 +666,8 @@ private static string Map(PropertyModel property)
649666 Type t when t == typeof ( double ) => "FLOAT" ,
650667 Type t when t == typeof ( float ) => "REAL" ,
651668
669+ Type t when t == typeof ( string [ ] ) || t == typeof ( List < string > ) => "JSON" ,
670+
652671 _ => throw new NotSupportedException ( $ "Type { property . Type } is not supported.")
653672 } ;
654673
0 commit comments