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
When type configured using ToSqlQuery has an owned type, EF Core generates incorrect query
EF Core Config
asyncTaskMain(){varc=newContext();c.Centres.First();//Invalid object name 'Centres'.}publicclassContext:DbContext{publicDbSet<Centre>Centres{get;set;}protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){base.OnModelCreating(modelBuilder);modelBuilder.Entity<Centre>(config =>{config.ToSqlQuery(@"SELECT c.Id, c.Name, cg.Guid FROM CENTRE c JOIN CentreGuid cg on cg.CentreId = c.Id ");config.OwnsOne(c =>c.Test, c =>{c.Property(c =>c.Guid).HasColumnName("Guid");});});}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder){optionsBuilder.UseLazyLoadingProxies().UseSqlServer(".").EnableSensitiveDataLogging(true);}}publicclassCentre{publicintId{get;set;}publicstringName{get;set;}publicGuidWrapperTest{get;set;}}publicclassGuidWrapper{publicGuidGuid{get;set;}}
Generated SQL
SELECT TOP(1) [u].[Id], [u].[Name], [c].[Id], [c].[Guid]
FROM (
SELECTc.Id, c.Name, cg.GuidFROM CENTRE c
JOIN CentreGuid cg oncg.CentreId=c.Id
) AS [u]
LEFT JOIN [Centres] AS [c] ON [u].[Id] = [c].[Id]
Here we can observe join to non existant table Centres. The join should eaither not be made and its data shoud be selected from the first part or it should be made to the same subquery as in the first part
When type configured using
ToSqlQuery
has an owned type, EF Core generates incorrect queryEF Core Config
Generated SQL
Here we can observe join to non existant table
Centres
. The join should eaither not be made and its data shoud be selected from the first part or it should be made to the same subquery as in the first partPossibly releated issue: #29300
Include provider and version information
EF Core version:
Database provider: Microsoft.EntityFrameworkCore.SqlServer 8.0.4
Target framework: .NET 8.0
The text was updated successfully, but these errors were encountered: