Skip to content

EF Core 9 Change Tracking stops working when [Projectable(UseMemberBody=)] is used in an Entity. #129

@kerimcharfi

Description

@kerimcharfi

Hi, I'm currently facing the issue that when I use [Projectable(UseMemberBody = nameof(InternalVersionTagString))] on one of the properties in my Entity class, the change tracking of EF CORE 9 stops working completely without errors, even for an unrelated property (e.g. public string? Name { get; set; } )

When using [Projectable] without UseMemberBody the problem does not arise, however this strategy doesnt work well with Hot Chocolate.

    [NotMapped]
    public uint VersionTag { get; set; }

    [GraphQLName("_versionTag")]
    [NotMapped]
    [Projectable(UseMemberBody = nameof(InternalVersionTagString))] <- when i comment this line out, the change tracking works again
    public string VersionTagString { get; set; }
    
    // We have to use this strategy of projectable because Hot Chocolate seems to skip lambdas in their projection engine
    // This leads to the behaviour that e.g. InternalVersionTagString is null until the dependency VersionTag is also fetched
    // The lambda is then used by hot chocolate as a resolver(called after query result arrived), regardless whether it has the [Projectable] Attribute
    private string InternalVersionTagString => VersionTag.ToString();

LOGS

2025-04-08 05:35:26 info: server.api.ItemController[0]
2025-04-08 05:35:26       Old Item name is Tester
2025-04-08 05:35:26 info: server.api.ItemController[0]
2025-04-08 05:35:26       ItemDto name is Testr
2025-04-08 05:35:26 info: server.api.ItemController[0]
2025-04-08 05:35:26       Item name is Testr
....
2025-04-08 05:35:26 info: server.api.ItemController[0]
2025-04-08 05:35:26       ChangeTracker HasChanges before SaveChanges: False

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions