@@ -79,21 +79,28 @@ public NpgsqlArrayMethodTranslator(NpgsqlSqlExpressionFactory sqlExpressionFacto
7979 // During preprocessing, ArrayIndex and List[] get normalized to ElementAt; so we handle indexing into array/list here
8080 if ( method . IsClosedFormOf ( Enumerable_ElementAt ) )
8181 {
82- // Indexing over bytea is special, we have to use function rather than subscript
83- if ( arguments [ 0 ] . TypeMapping is NpgsqlByteArrayTypeMapping )
82+ return arguments [ 0 ] . TypeMapping switch
8483 {
85- return _sqlExpressionFactory . Function (
86- "get_byte" ,
87- [ arguments [ 0 ] , arguments [ 1 ] ] ,
88- nullable : true ,
89- argumentsPropagateNullability : TrueArrays [ 2 ] ,
90- typeof ( byte ) ) ;
91- }
92-
93- // Try translating indexing inside JSON column
94- // Note that Length over PG arrays (not within JSON) gets translated by QueryableMethodTranslatingEV, since arrays are primitive
95- // collections
96- return _jsonPocoTranslator . TranslateMemberAccess ( arguments [ 0 ] , arguments [ 1 ] , method . ReturnType ) ;
84+ // Indexing over bytea is special, we have to use function rather than subscript
85+ NpgsqlByteArrayTypeMapping
86+ => _sqlExpressionFactory . Function (
87+ "get_byte" ,
88+ [ arguments [ 0 ] , arguments [ 1 ] ] ,
89+ nullable : true ,
90+ argumentsPropagateNullability : TrueArrays [ 2 ] ,
91+ typeof ( byte ) ) ,
92+
93+ NpgsqlArrayTypeMapping typeMapping
94+ => _sqlExpressionFactory . ArrayIndex (
95+ arguments [ 0 ] ,
96+ _sqlExpressionFactory . GenerateOneBasedIndexExpression ( arguments [ 1 ] ) ,
97+ nullable : true ) ,
98+
99+ // Try translating indexing inside JSON column
100+ // Note that Length over PG arrays (not within JSON) gets translated by QueryableMethodTranslatingEV, since arrays are primitive
101+ // collections
102+ _ => _jsonPocoTranslator . TranslateMemberAccess ( arguments [ 0 ] , arguments [ 1 ] , method . ReturnType )
103+ } ;
97104 }
98105
99106 if ( method . IsClosedFormOf ( Enumerable_SequenceEqual )
0 commit comments