@@ -219,7 +219,7 @@ when entityQueryRootExpression.GetType() == typeof(EntityQueryRootExpression)
219
219
Check . DebugAssert ( sqlParameterExpression is not null , "sqlParameterExpression is not null" ) ;
220
220
return TranslateCollection (
221
221
sqlParameterExpression ,
222
- elementTypeMapping : null ,
222
+ property : null ,
223
223
char . ToLowerInvariant ( sqlParameterExpression . Name . First ( c => c != '_' ) ) . ToString ( ) )
224
224
?? base . VisitExtension ( extensionExpression ) ;
225
225
@@ -265,20 +265,24 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
265
265
if ( translated == QueryCompilationContext . NotTranslatedExpression )
266
266
{
267
267
// Attempt to translate access into a primitive collection property (i.e. array column)
268
- if ( _sqlTranslator . TryTranslatePropertyAccess ( methodCallExpression , out var propertyAccessExpression )
269
- && propertyAccessExpression is SqlExpression
268
+
269
+ // TODO: We should be detecting primitive collections by looking at GetElementType() of the property and not at its type
270
+ // mapping; but #31469 is blocking that for shadow properties.
271
+ if ( _sqlTranslator . TryTranslatePropertyAccess ( methodCallExpression , out var translatedExpression , out var property )
272
+ && property is IProperty regularProperty
273
+ && translatedExpression is SqlExpression
270
274
{
271
- TypeMapping . ElementTypeMapping : RelationalTypeMapping elementTypeMapping
272
- } collectionPropertyAccessExpression )
275
+ TypeMapping . ElementTypeMapping : RelationalTypeMapping
276
+ } sqlExpression )
273
277
{
274
- var tableAlias = collectionPropertyAccessExpression switch
278
+ var tableAlias = sqlExpression switch
275
279
{
276
280
ColumnExpression c => c . Name [ ..1 ] . ToLowerInvariant ( ) ,
277
281
JsonScalarExpression { Path : [ .., { PropertyName : string propertyName } ] } => propertyName [ ..1 ] . ToLowerInvariant ( ) ,
278
282
_ => "j"
279
283
} ;
280
284
281
- if ( TranslateCollection ( collectionPropertyAccessExpression , elementTypeMapping , tableAlias ) is
285
+ if ( TranslateCollection ( sqlExpression , regularProperty , tableAlias ) is
282
286
{ } primitiveCollectionTranslation )
283
287
{
284
288
return primitiveCollectionTranslation ;
@@ -316,17 +320,15 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
316
320
/// collections.
317
321
/// </remarks>
318
322
/// <param name="sqlExpression">The expression to try to translate as a primitive collection expression.</param>
319
- /// <param name="elementTypeMapping">
320
- /// The type mapping of the collection's element, or <see langword="null" /> when it's not known (i.e. for parameters).
323
+ /// <param name="property">
324
+ /// If the primitive collection is a property, contains the <see cref="IProperty" /> for that property. Otherwise, the collection
325
+ /// represents a parameter, and this contains <see langword="null" />.
321
326
/// </param>
322
327
/// <param name="tableAlias">
323
328
/// Provides an alias to be used for the table returned from translation, which will represent the collection.
324
329
/// </param>
325
330
/// <returns>A <see cref="ShapedQueryExpression" /> if the translation was successful, otherwise <see langword="null" />.</returns>
326
- protected virtual ShapedQueryExpression ? TranslateCollection (
327
- SqlExpression sqlExpression ,
328
- RelationalTypeMapping ? elementTypeMapping ,
329
- string tableAlias )
331
+ protected virtual ShapedQueryExpression ? TranslateCollection ( SqlExpression sqlExpression , IProperty ? property , string tableAlias )
330
332
=> null ;
331
333
332
334
/// <summary>
0 commit comments