oracle / dotnet-db-samples

.NET code samples for Oracle database developers #OracleDotNet
http://otn.oracle.com/dotnet
MIT License
413 stars 191 forks source link

ExecuteUpdate: Alias is reused when table-names start with same letter #284

Closed anoordover closed 1 year ago

anoordover commented 1 year ago

I execute an ExecuteUpdate in Oracle EF Core (I don't know if this is an Oracle EF Core or EF Core issue). When the Linq statement uses two tables have the same first letter in the table-name the same alias is being reused. eg (when the table-name are XYZ_CREDITS and XYZ_DECLARATIONS):

var r = db.Credits.Where(c => c.Id == 1) .Select(c => new { credit = c, declaration = db.Declarations .First(d => d.Reference == c.ReferenceDeclaration) }) .ExecuteUpdate(calls => calls.SetProperty( c => c.credit.DeclarationId, c => c.declaration.Id)); the SQL begin generated seems to be:

UPDATE "XYZ_CREDITS" "x" SET "x"."DeclarationId" = ( SELECT "x"."Id" FROM "XYZ_DECLARATIONS" "x" WHERE "x"."Reference" = ""."ReferenceDeclaration" FETCH FIRST 1 ROWS ONLY) WHERE "x"."Id" = 1

See https://github.com/anoordover/OracleDbDemo In the repo I mention 3 issues. This issue is only about the re-use of the same alias.

alexkeh commented 1 year ago

Thanks for reporting. I've reproduced the problem with the duplicative alias and filed bug 35325121 to have the root cause investigated further.

alexkeh commented 1 year ago

After further investigation, this is a generic EF Core issue that is also replicable with the EF Core SQL Server provider. A Github bug is filed for this testcase, which MS has currently scheduled to fix by EF 8.0.0 (November 2023). https://github.com/dotnet/efcore/issues/30856