You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
List property causes inclusion of addition columns that are not used in the projection.
Hi there, I have a strange issue going on when I include a List property in the Select when querying the DB. It includes all the additional columns even if they are not used in the projection.
I'm applying DDD, so I have my "Datamodel" Entity with a lot of Owned Entity relations defined:
and then each of the Owned Entities is configured like this:
privatestaticvoidConfigureClassifications(EntityTypeBuilder<Datamodel>builder){builder.OwnsMany(m =>m.Classifications, cb =>{cb.WithOwner().HasForeignKey("DatamodelId");cb.HasKey(classification =>classification.Id);cb.Property(classification =>classification.Id).ValueGeneratedNever();cb.OwnsOne<TranslatableProperty>(classification =>classification.Name, nb =>nb.Property<Dictionary<string,string>>("_translations").HasColumnName("NameTranslations").HasValueJsonConverter());});}
Now I understand that Owned Entities are auto-included, now when querying this isn't always needed, and with the Select statement, you can select the specific data that you need, like this:
// Works - only selects the [Id] from the table.varmodels=await_readRepository.Queryable().Select(model =>new{model.Id,}).ToListAsync(cancellationToken);
(Queryable() returns a DbSet with .AsNoTracking())
this call results in the following SQL:
SELECT [d].[Id]
FROM [Datamodel] AS [d]
WHERE [d].[TenantId] = @__ef_filter__Id_0
Including one of the owned entities in the select, also works fine:
SELECT [d].[Id], [c].[Id], [c].[CreatedOn], [c].[DatamodelId], [c].[ExternalId], [c].[ExternalReference], [c].[Index], [c].[TechnicalName], [c].[UpdatedOn], [c].[NameTranslations]
FROM [Datamodel] AS [d]
LEFT JOIN [Classification] AS [c] ON [d].[Id] = [c].[DatamodelId]
WHERE [d].[TenantId] = @__ef_filter__Id_0
ORDER BY [d].[Id]
But the moment I include that SupportedLocales property, all of the other additional columns and Owned Entities are included in the SQL, even when they're not needed.
// Doesn't work - Also includes all the owned entities.varmodels=await_readRepository.Queryable().Select(model =>new{model.Id,model.SupportedLocales,// List<string>}).ToListAsync(cancellationToken);
Is this a bug or is this intended behavior? Is there a way to query the SupportedLocales without including everything, this is causing performance issues.
I've tried .AsNoTracking() and .IgnoreAutoIncludes(), but nothing seems to work.
Thijs153
changed the title
List<string> property causes inclusion of addition columns that are not used in the projection.
List<string> property causes inclusion of additional columns that are not used in the projection.
Oct 1, 2024
List property causes inclusion of addition columns that are not used in the projection.
Hi there, I have a strange issue going on when I include a List property in the
Select
when querying the DB. It includes all the additional columns even if they are not used in the projection.I'm applying DDD, so I have my "Datamodel" Entity with a lot of Owned Entity relations defined:
Note the
SupportedLocales
property.This Datamodel has the following ef configuration:
and then each of the Owned Entities is configured like this:
Now I understand that Owned Entities are auto-included, now when querying this isn't always needed, and with the
Select
statement, you can select the specific data that you need, like this:(
Queryable()
returns a DbSet with .AsNoTracking())this call results in the following SQL:
Including one of the owned entities in the select, also works fine:
results into:
But the moment I include that SupportedLocales property, all of the other additional columns and Owned Entities are included in the SQL, even when they're not needed.
Is this a bug or is this intended behavior? Is there a way to query the SupportedLocales without including everything, this is causing performance issues.
I've tried .AsNoTracking() and .IgnoreAutoIncludes(), but nothing seems to work.
Include provider and version information
EF Core version:
"Microsoft.EntityFrameworkCore" Version="8.0.2"
"Microsoft.EntityFrameworkCore.Design" Version="8.0.0"
"Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2"
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Windows 11
IDE: JetBrains Rider 2024.2
The text was updated successfully, but these errors were encountered: