I’m using Radzen Blazor Studio with a database-first, multi-tenant Blazor Server app. After inferring new tables, I reviewed the generated CSV and Excel actions. In our project, both actions query the data service, and neither the action nor the generated service query restricts the results to the signed-in user’s TenantId.
I’d expect a user who can export a table to receive only their tenant’s rows. That restriction should be applied on the server and hold even when the export request has no grid filter.
Is there a Studio multi-tenancy setting or supported hook that should apply the current tenant to generated exports automatically? If so, what configuration does the generator expect? If this case is missing from the generator, could you update it so CSV and Excel exports consistently enforce the configured tenant scope after every database inference?
There is no Studio setting for this - the supported hook is the On<EntitySet>Read partial method of the generated service. Every generated export action gets its data through Get<EntitySet>(), which calls that partial method, so a filter added there applies to both exports and pages, and it runs on the server whatever the request contains.
Put it in your own partial class file (for example Services/MyDbService.Custom.cs). Studio doesn't overwrite that file when you infer the database again:
public partial class MyDbService
{
partial void OnOrdersRead(ref IQueryable<Order> items)
{
var tenantId = GetCurrentTenantId(); // your own lookup for the signed-in user
// No tenant means no rows, rather than all rows.
items = tenantId == null
? items.Where(i => false)
: items.Where(i => i.TenantId == tenantId);
}
}
Two things to watch for:
Resolving the tenant: export requests are plain HTTP requests to a controller, not part of the Blazor circuit, so resolve the user from HttpContext.User there (via IHttpContextAccessor). You can add a second constructor in your partial class that takes the extra dependency and chains to the generated one.
Covering every table at once: if most of your tables have a TenantId, an EF Core global query filter is less work than one partial method per table. Add it in the OnModelBuilding partial method of the generated context, with HasQueryFilter. It then applies to every query against that entity, including single-record reads.
Add also [Authorize] to the export controller in a partial class of your own, so only signed-in users can request exports at all:
[Authorize]
public partial class ExportMyDbController
{
}
Thanks, that confirms we’re using the supported approach. We’ve already handled this in a partial class that survives re-inference. Would you consider having Studio generate the tenant filter automatically when multi-tenancy is configured and a newly inferred table has a TenantId? I’d expect its CSV and Excel exports to return only the signed-in tenant’s rows, even when the request has no grid filter.