Question on possibility of general RelationalShapedQueryCompilingExpressionExpressionVisitor updates

Aperta
#39,534 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
backend, databases

Direzione di ricerca

Read src/Shared/ExpressionExtensions.cs and src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs, focusing on the two proposed changes for handling StructuralTypeProjectionExpression and enumerable cardinality results. Check how these changes affect relational query compilation and whether they avoid patching the visitor for custom query translation and SQL generation factories. Done means deciding whether the general changes are appropriate for EF Core and defining their compatibility impact across releases.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

customer-reported
Question

While exploring the possibility of passing a custom Expression with Enumerable cardinality results
through the EFCore pipeline, it became necessary to implement some patches related to RelationalShapedQueryCompilingExpressionExpressionVisitor and ExpressionExtensions.

Take a look at code fragments marked by // ++++++++++++++++ >

Does it make sense to create PR to have such change in current and future releases in order to do not patch
RelationalShapedQueryCompilingExpressionExpressionVisitor?

According to research results it would be enough to implement only two custom IQueryableMethodTranslatingExpressionVisitorFactory and IQuerySqlGeneratorFactory with such changes.

Your code
// efcore\src\Shared\ExpressionExtensions.cs

internal static class ExpressionExtensions
{
    // ...
	
    public static T GetConstantValue<T>(this Expression expression)
        => RemoveConvert(expression) switch
        {
		    // ++++++++++++++ >
            StructuralTypeProjectionExpression projection => (T)(IReadOnlyDictionary<IProperty, ColumnExpression>)typeof(StructuralTypeProjectionExpression).GetField("_propertyExpressionMap", BindingFlags.NonPublic| BindingFlags.Instance | BindingFlags.GetField)!.GetValue(projection)!,
		    // ++++++++++++++ < 
            ConstantExpression constantExpression => (T)constantExpression.Value!,
#pragma warning disable EF9100 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
            LiftableConstantExpression liftableConstantExpression => (T)liftableConstantExpression.OriginalExpression.Value!,
#pragma warning restore EF9100 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
            _ => throw new InvalidOperationException()
        };
		
	// ...
}


// efcore\src\EFCore.Relational\Query\
// RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs
        protected override Expression VisitBinary(BinaryExpression binaryExpression)
        {
            switch (binaryExpression)
            {
                case { NodeType: ExpressionType.Assign, Left: ParameterExpression parameterExpression }
                    when parameterExpression.Type == typeof(MaterializationContext):
                    {
                        var newExpression = (NewExpression)binaryExpression.Right;

                        if (newExpression.Arguments[0] is ProjectionBindingExpression projectionBindingExpression)
                        {
                            var propertyMap = GetProjectionIndex(projectionBindingExpression) switch
                            {
					// ++++++++++++++++ > 
                                IReadOnlyDictionary<IProperty, ColumnExpression> pp => pp.Select((x, i) => (x, i)).ToDictionary(x => (IPropertyBase)x.x.Key, x => x.i),
					// ++++++++++++++++ <
                                IDictionary<IPropertyBase, int> p => p,
                                QueryableJsonProjectionInfo pi => pi.PropertyIndexMap,
                                _ => throw new UnreachableException()
                            };
Stack traces

Verbose output

EF Core version

10.0.0

Database provider

No response

Target framework

.NET 10

Operating system

No response

IDE

No response

Lingua principale
C#
Stelle
14.8k
Fork
3.4k
Merge medio
3g 18h
PR unite (30g)
159

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dotnet/efcore

Tutte le issue di dotnet/efcore

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.