-
-
Notifications
You must be signed in to change notification settings - Fork 274
Deleting a model with a composite key bypassing multitenancy #520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting this issue. I'll take a closer look tomorrow. Finbuckle doesn't automatically add tenant id to the key but has a helper function to do so for entities that works in some but not all cases due to EF Core constraint priorities. I'll have a more detailed answer for you soon. |
Thanks for swift reply. Are you referring to the Keys and Indexes section of https://www.finbuckle.com/MultiTenant/Docs/v6.6.0/EFCore docs? I was going to try that as a solution, but if it doesn't work I'll get you some nice repro code :) |
Still ran into issues with adjusting keys as per the https://www.finbuckle.com/MultiTenant/Docs/v6.6.0/EFCore Keys and Indexes docs. Working on a fork of the repo with some tests added that reproduce the issues we're running into. |
Here's a fork with some tests that surface some of the issues we're running into: https://github.com/domn1995/Finbuckle.MultiTenant/blob/main/test/Finbuckle.MultiTenant.EntityFrameworkCore.Test/CompositeKeyTests/CompositeKeysShould.cs I would expect all of these tests to pass but only the |
Ok, having dug in I can explain some parts but not all. Thank you for isolating the behavior so well.
I hope this help and thanks for all the details. |
Thanks so much for looking into this so quickly! We're moving forward with explicit Thanks again for the prompt support. |
Happy to help and thank you for the sponsorship. |
Alright I removed the generator and filed a bug with the efcore team. They said only on "adding" a tracked entity will it pick up a shadow key property. I voted on an issue to expand that to any method which attaches an entity. The best option here is to do exactly what you did -- or to use the Thanks! |
When deleting a multitenant entity that's configured to use a composite key in our database migrations scripts and with the EF Core
ModelBuilder
isn't respecting multitenancy.The database constraint in our migrations script looks like:
ALTER TABLE ONLY public."Examples" ADD CONSTRAINT "PK_Examples" PRIMARY KEY ("Number", "TenantId", "Username");
Our EF Core classes look like:
When we delete an
ExampleModel
from the context, all otherExampleModel
s with the sameUsername
andNumber
are deleted as well, even with differentTenantId
s.Should
Finbuckle
be adding theTenantId
to the composite key? Is there a way we can add it as part of the model builder such that the call tomodelBuilder
mirrors our database constraints? Is there some other solution?The text was updated successfully, but these errors were encountered: