Skip to content

Entity returned from server is left in a Detached state when it references itself #87

@erestor

Description

@erestor

em._attachEntityCore(targetEntity, EntityState.Unchanged, mergeStrategy);

When an object referencing itself is returned from the EFCore server, it doesn't correctly use $ref (IMO EFCore bug) and the two objects are in the JSON instead of one, e.g. { 'id': 1, 'ownerId': 1, 'owner': { 'id': 1, 'ownerId': 1, 'owner': null, ... }, ... }. The mapping in Breeze results in entityAspect to have state 'Detached' and an empty entityManager. This is because the reference object is processed first (due to recursion in visitAndMerge) and stored. It is then correctly recognized inside _attachEntityCore and returned, but the return value is disregarded, leaving the original entity being mapped detached.

Suggested fix: replace the line with targetEntity = em._attachEntityCore(targetEntity, EntityState.Unchanged, mergeStrategy);

This would be in accord with EntityManager:

attachedEntity = this._attachEntityCore(entity, esSymbol, msSymbol);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions