-
-
Notifications
You must be signed in to change notification settings - Fork 269
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
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
Comments
Actually this is using an old version of Finbuckle.MultiTenant. I haven't gotten around to upgrading due to breaking changes. Still weird that this would suddenly break... |
Hi, I think it should be as simple as setting |
I am just a little hesitant doing this knowing it used to work without that setting. |
FYI I had the same issue "1 modified entities with Tenant Id not set." Although I was just updating an entity, I didn't delete anything... (at least not in the method where this error was throwing). After some debugging, I found a bug in my code, where I deleted another entity twice (in the same dbcontext in an unrelated event handler). When I fixed the bug, so the delete was only done once, everything worked again. I also think this one is somehow related: #651 |
Turns out it was something very strange... public abstract class BaseEntity : BaseEntity<Guid>
{
protected BaseEntity() => Id = RT.Comb.Provider.PostgreSql.Create();
} I removed the BaseEntity and made the BaseEntity implement IEntity<Guid> and same for the AuditableEntity<Guid> and this somehow caused this problem... |
Thanks for the update. I'm glad you got it working for you but I would like to understand what was going on so let me know if you see anything else. Finbuckle is just looking at the db context's tracked changes and if it sees any that are missing the tenant it optionally throws that error. The only thing I can think of is if a delete is cascading or some other code is adjusting tracking entries outside of your own. |
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:
and after that I call
SaveChangesAsync
. When debuggingEnforceMultiTenant
I can see that it is this NIC entity which is in thenotSetModified
List.The text was updated successfully, but these errors were encountered: