Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

OracleDbDemo for ExecuteUpdate findings

Using join

            var s = db.Credits.Where(c => c.Id == 1)
                .Join(db.Declarations,
                    c => c.DeclarationReference,
                    d => d.Reference,
                    (credit, declaration) => new {credit, declaration})
                .ExecuteUpdate(calls => calls.SetProperty(
                    c => c.credit.DeclarationId,
                    c => c.declaration.Id));

The SQL being generated is incorrect

      UPDATE "Credits" "c"
      SET "c"."DeclarationId" = "d"."Id"
      FROM "Declarations" "d"
      WHERE (("c"."DeclarationReference" = "d"."Reference") AND ("c"."Id" = 1))

Using select

            var r = db.Credits.Where(c => c.Id == 1)
                .Select(c => new
                {
                    credit = c,
                    declaration = db.Declarations
                        .First(d => d.Reference == c.DeclarationReference)
                })
                .ExecuteUpdate(calls => calls.SetProperty(
                    c => c.credit.DeclarationId,
                    c => c.declaration.Id));

This code generates correct SQL

      UPDATE "Credits" "c"
      SET "c"."DeclarationId" = (
          SELECT "d"."Id"
          FROM "Declarations" "d"
          WHERE "d"."Reference" = "c"."DeclarationReference"
          FETCH FIRST 1 ROWS ONLY)
      WHERE "c"."Id" = 1

Using select with two entities/tables starting with same letter

This issue is solved in version 7.0.11 of EF Core.

            var r = db.Contestations.Where(c => c.Id == 1)
                .Select(c => new
                {
                    contestation = c,
                    credit = db.Credits
                        .First(d => d.Reference == c.CreditReference)
                })
                .ExecuteUpdate(calls => calls.SetProperty(
                    c => c.contestation.CreditId,
                    c => c.credit.Id));

In this sql-statement the same alias is being reused

      UPDATE "Contestations" "c"
      SET "c"."CreditId" = (
          SELECT "c"."Id"
          FROM "Credits" "c"
          WHERE "c"."Reference" = "c"."CreditReference"
          FETCH FIRST 1 ROWS ONLY)
      WHERE "c"."Id" = 1

This issue is solved in 7.0.11. The sql-statement being generated is

      UPDATE "Contestations" "c"
      SET "c"."CreditId" = (
          SELECT "c0"."Id"
          FROM "Credits" "c0"
          WHERE "c0"."Reference" = "c"."CreditReference"
          FETCH FIRST 1 ROWS ONLY)
      WHERE "c"."Id" = 1

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages