-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EF Core select all columns in SQL when a DTO mapper is called on Select() #6
Labels
ef-core
Issue related to Entity Framework (EF) Core
Comments
I have published a NuGet package with the solution proposed by Ivan Stoev (see https://stackoverflow.com/a/62138200). |
MrDave1999
added a commit
that referenced
this issue
Aug 9, 2022
MrDave1999
added a commit
that referenced
this issue
Aug 9, 2022
This attribute indicates which methods are to be decompiled.
MrDave1999
added a commit
that referenced
this issue
Aug 9, 2022
MrDave1999
added
the
needs review
Issue or pull request that need review or further investigation
label
Aug 31, 2022
In EF Core 7.0 added Interception to modify the LINQ expression tree, so the custom code should be simpler: using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace Microsoft.EntityFrameworkCore
{
public static class DelegateDecompilerDbContextOptionsBuilderExtensions
{
public static DbContextOptionsBuilder AddDelegateDecompiler(this DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.AddInterceptors(new DelegateDecompilerQueryPreprocessor());
}
}
namespace Microsoft.EntityFrameworkCore.Query
{
using System.Linq.Expressions;
using DelegateDecompiler;
public class DelegateDecompilerQueryPreprocessor : IQueryExpressionInterceptor
{
Expression IQueryExpressionInterceptor.QueryCompilationStarting(Expression queryExpression, QueryExpressionEventData eventData)
=> DecompileExpressionVisitor.Decompile(queryExpression);
}
} Reference: https://stackoverflow.com/a/62138200. |
MrDave1999
removed
the
needs review
Issue or pull request that need review or further investigation
label
Dec 28, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following LINQ:
back-end/src/Features/Users/UserRepository.cs
Lines 28 to 38 in 9a93908
EF Core translates it to:
In this case EF Core selects the columns associated to
UserResetPasswordDto
.But when the mapper is called in the
Select
method:EF Core translates it to:
EF Core selects ALL columns. The mapper code is:
back-end/src/Features/Users/UserMapper.cs
Lines 64 to 71 in 9a93908
There is a possible solution in this StackOverflow answer: https://stackoverflow.com/a/62138200 (must be tested)
This problem is also mentioned here: dotnet/efcore#24509
The text was updated successfully, but these errors were encountered: