Exception thrown while attempting to evaluate the LINQ query parameter expression #792
-
Hello everyone, hope someone can help me with the following problem. I am working on an app where the backend is based on the dotnet-webapi-starter-kit. This template has a db seeder. When the application starts and the ApplicationDbSeeder class is executed, I get an error in the SeedRolesAsync method when the following code is executed
I get this error: "An exception was thrown while attempting to evaluate the LINQ query parameter expression 'value(Finbuckle.MultiTenant.EntityFrameworkCore.FinbuckleEntityTypeBuilderExtensions+ExpressionVariableScope).Context.TenantInfo'. See the inner exception for more information." The inner exception is: "Object reference not set to an instance of an object." Finbuckle is configured this way:
I have noticed that the same error happens whenever LINQ code is executed. As an example, SeedRolesAsync is called by the following method
If I comment out SeedRolesAsync the same error happens in the SeedAdminUserAsync method when this line is executed
The same happens if I do the following
Any idea on what may be the problem? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi, so the root problem is that it doesn’t know the tenant at the time the db context was created. Typically in seeding it is not part of an actual request or user action so there is no tenant that makes sense. is the data you want to seed per tenant or global? For the former, one option I’ve used successfully is to loop through my tenants and create a standalone db context for the current tenant and deed it as needed. Also I reused this logic for any new tenant created to seed its data at the time the tenant was registered. For the latter, I’ve used a dummy or default tenant that allows me to get the db context to set non per tenant data as needed but isn’t a real tenant/customer. |
Beta Was this translation helpful? Give feedback.
-
I have the same ploblem, i dont know how resolve the proble of the current tenant |
Beta Was this translation helpful? Give feedback.
Hi, so the root problem is that it doesn’t know the tenant at the time the db context was created.
Typically in seeding it is not part of an actual request or user action so there is no tenant that makes sense. is the data you want to seed per tenant or global?
For the former, one option I’ve used successfully is to loop through my tenants and create a standalone db context for the current tenant and deed it as needed. Also I reused this logic for any new tenant created to seed its data at the time the tenant was registered.
For the latter, I’ve used a dummy or default tenant that allows me to get the db context to set non per tenant data as needed but isn’t a real tenant/customer.