Can't update record
See original GitHub issueWhen trying to update a record for a simple class, I am getting the following error message:
MultiTenantException: 1 modified entities with TenantId not set.
Looking directly at the database, I can see that the TenantID is set just fine when the record was created.
Any ideas why this may be happening?
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Troubleshoot errors when updating data in query or form
To resolve this problem, you must join the tables correctly so you can update them. When the field that you want to update...
Read more >Cannot Update Record in PostgreSQL
The UPDATE statement will only work if you have data with matching criteria in the table already. If you are adding records, you...
Read more >Access 2016 - The form won't allow updating a record
I have an "Edit" button to update individual records and even pressing that the form won't allow me to update any fields on...
Read more >cannot update record, get stuck - mysql
cannot update record, get stuck · 1. EXPLAIN your query, maybe you have index problems · How can for example an INSERT wait...
Read more >How To Fix Access Database Not Updating Issue?
To fix this issue, just add a unique index or primary key in the linked table. If you don't have the Update Data...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi again, I see the issue.
Because you are using
_context.Update(siteSettings)
to do a direct update the tenant id is not set on the “untracked” entity because tenant id is a shadow property in EFCore.You have a few options:
TenantNotSetMode.Overwrite
which will plug in the tenant Id when saving. Note that this settings will be in effect for any future saves on the same dbcontext in the request.You can add a property to the
SiteSettings
class calledTenantId
which Finbuckle.MultiTenant will use, then if you make sure it gets passed around in the Get/Post requests the tenant Id should be there when you callUpdate
andSaveChanges
.Avoid using
Update
and instead get the entity from the database via EFCore then update this “tracked” entity, then save it.I think option 1 is probably the best way to go here.
Thanks for the explanation, really appreciate your help.