Skip to content

Owned entities FKs not matching PK casing on creation #37023

Closed

Description

@Xriuk

Bug description

When adding a new entity without autogenerated keys to the DB and then changing the key before saving to uppercase FKs for owned entities (didn't test it with non-owned entities) stay lowercase.
This does not happen if the key gets changed completely to a different value, then the owned entities are updated accordingly.

Your code

var entity = new MyEntity{
  Key = "test",
  ...
  MyOwnedCollection = [
    ...
  ]
};

db.Add(entity);

entity.Key = entity.Key.ToUpper();

db.SaveChanges();

// entity gets inserted with PK Key = "TEST", while the owned entities with FK MyEntityKey = "test"

EF Core version

8.0.16

Database provider

Microsoft.EntityFrameworkCore.SqlServer

Target framework

.NET 8.0

Activity

  1. Xriuk commented on Oct 24, 2025

    @Xriuk
    Author

    Not sure if related to #32898
    Also I understand that by default it seems that case-insensitive comparison is used for SQL server keys but still imho EF Core should be consistent at least when inserting keys into the DB.

  2. added this to the 11.0.0 milestone on Oct 24, 2025
  3. added theissue type on Oct 24, 2025
  4. added a commit that references this issue on Jul 9, 2026
    f97f9f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions