Skip to content

Error when saving an entity with a populated collection in a 1-to-many EF Core relationship: Tenant ID not set in Finbuckle.MultiTenant #908

Open
@JonasDev17

Description

When adding an entity to a collection property of another entity (representing a 1-to-many relationship mapped by EF Core) and attempting to save changes, the following error occurs:

Finbuckle.MultiTenant.MultiTenantException : 1 modified entities with Tenant Id not set.

Is this expected? This used to work but something changed (in my code) but I have no clue what it could be.
The workaround is to add it through the DbContext.

Is there some condition for this to work?

This is the method I am calling on my entity:

public Device AddNetworkInterfaceController(Guid ipAddressId, string? macAddress, string? name, string? description)
{
    var deviceNetowrkCard = new NetworkInterfaceController(this.Id, ipAddressId, macAddress, name, description);
    NetworkInterfaceControllers.Add(deviceNetowrkCard);
    return this;
}

and after that I call SaveChangesAsync. When debugging EnforceMultiTenant I can see that it is this NIC entity which is in the notSetModified List.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions