-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
ExecuteUpdate: Duplicate table alias in generated Update query #30856
Comments
@ajcvickers Please look into this bug. |
Simplified repro: await using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
_ = ctx.Contestations
.Select(c => new
{
Contestation = c,
Credit = ctx.Credits.First(d => d.Reference == c.CreditReference)
})
.ExecuteUpdate(calls => calls.SetProperty(c => c.Contestation.CreditId, c => c.Credit.Id));
public class BlogContext : DbContext
{
public virtual DbSet<Credit> Credits { get; set; }
public virtual DbSet<Contestation> Contestations { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(@"Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
public class Contestation
{
public long Id { get; set; }
public string Reference { get; set; }
public string CreditReference { get; set; }
public long? CreditId { get; set; }
}
public class Credit
{
public long Id { get; set; }
public string Reference { get; set; }
} SQL: UPDATE [c]
SET [c].[CreditId] = (
SELECT TOP(1) [c].[Id]
FROM [Credits] AS [c]
WHERE [c].[Reference] = [c].[CreditReference])
FROM [Contestations] AS [c] @maumar are you the best person to take a look? |
@ajcvickers , @AndriySvyryd Any plan to fix this in next EF 7 patch release? |
@indrajitjadeja we have to first investigate this and understand what the fix would entail. |
this is now fixed (this must have had the same root cause as one of the other issues around alias uniquification that we fixed) - repro provided by @roji now yields the following sql: UPDATE [c]
SET [c].[CreditId] = (
SELECT TOP(1) [c0].[Id]
FROM [Credits] AS [c0]
WHERE [c0].[Reference] = [c].[CreditReference] OR ([c0].[Reference] IS NULL AND [c].[CreditReference] IS NULL))
FROM [Contestations] AS [c] |
Duplicate of #31078 |
we have the same issue for Select and OrderBy (x => x.NestedProperty.ToLower()) query, is any work around exists since we could not update EF to v7 because of spanner database |
EF Core query result in Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name
Issue #30358 might be similar, for which fix #30486 is merged to release/7.0 and also available in EF Core 8.0.0-preview.3.23174.2 NuGet version link
But
ExecuteUpdate
method is still generating duplicate alias in UPDATE statement ( issue is replicating in EF Core 8 preview 3 version and EF core 7.0.5 version)Generated Update query:
Sample code
Stack trace
provider and version information
EF Core version: 7.0.5 & 8.0.0-preview.3.23174.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0
Operating system: Windows 11
IDE: (e.g. Visual Studio 2022 17.5.2)
The text was updated successfully, but these errors were encountered: