Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

For multi-tenant reports, an EF Core global query filter is a useful default—not an unbypassable security boundary. To prevent a mistaken or alternate application query from returning another tenant’s rows, enforce the tenant predicate independently in the database for every relevant data path, using the application’s actual database identity and session setup.

What EF Core filters do—and what they do not

EF Core global query filters automatically scope entity queries using a condition such as a tenant discriminator matching the tenant ID available to the DbContext. This helps make tenant scoping the normal behavior of queries that pass through EF Core. Microsoft’s example uses a context-level tenant ID and a filter on the entity: Global Query Filters – EF Core.

A global filter is application-level behavior, not database row-level security (RLS). EF Core allows filters to be disabled selectively, and data-access paths that do not use the filtered entity query do not automatically inherit its predicate. A report that uses raw SQL, a stored procedure, or another route therefore needs an independently verified control. Do not describe a global filter as something users cannot bypass.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How database row-level security adds an enforcement boundary

SQL Server RLS attaches a security policy to a table and uses a predicate function to filter rows in the database. A predicate can use a tenant value held in SQL SESSION_CONTEXT; the database then evaluates that policy when the relevant table is accessed. See Microsoft’s guidance on implementing row-level security with session context.

#1 Best Overall
Sale
Database Security
  • Used Book in Good Condition

For this to protect reports, the database must receive the correct tenant context for the connection executing each query, and the policy must cover the tables and operations those reports use. The application’s identity-to-session mapping and connection-pooling lifecycle are part of the security design: validate that a connection cannot execute a tenant query with a missing, stale, or incorrect tenant value. The cited documentation establishes the SQL Server mechanism, but not a complete ASP.NET Core implementation recipe.

Microsoft’s Data API Builder quickstart demonstrates mapping an authenticated claim into SQL session context before a query: Quickstart: Use SQL row-level security with Data API builder. That is a Data API Builder integration example, not built-in ASP.NET Core behavior. An ASP.NET Core application must implement and test its own connection and session setup.

Set up the application-level default

For a shared database with a tenant discriminator, resolve the tenant from trusted request identity and pass it through the DbContext construction and lifetime path. A simplified filter has this shape:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
public class MultitenancyContext(string tenantId) : DbContext
{
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Blog>().HasQueryFilter(b => b.TenantId == tenantId);
    }
}

This example illustrates the default query guardrail; it does not create database-enforced isolation. Confirm the EF Core version before relying on filter composition behavior. Before EF Core 10, multiple filters must be combined with && in one filter expression. Microsoft labels named filters as an EF Core 10 preview feature in its filter documentation.

Choose a tenant data layout

EF Core documents three broad approaches. The choice affects where isolation is enforced and how the reporting stack is configured; it does not remove the need to verify every report’s access path. See EF Core multi-tenancy guidance.

Layout Isolation approach EF Core considerations
Shared tables with a tenant discriminator Rows share tables and carry a tenant key. Application filters can scope ordinary EF queries; add database enforcement when query mistakes must not expose another tenant’s rows. Global query filters are supported for discriminator-column tenancy.
Database per tenant Each tenant uses a separate database and the application connects to the correct one. EF Core documents this as a supported approach. Provisioning, migrations, connection management, and cross-tenant reporting need architectural planning; the cited guidance does not quantify those operational trade-offs.
Schema per tenant Tenants use separate schemas within a database. EF Core says this is not directly supported and is not a recommended solution.

Audit every reporting path, not just LINQ

Build the review around the data paths that can return tenant rows. A correct filter or RLS policy on one path does not demonstrate that the others are covered.

  • EF entity queries: confirm the context receives the trusted tenant ID and that filters have not been disabled.
  • Raw SQL and stored procedures: verify that database policy still applies and that the session tenant value is established for the executing connection.
  • Exports and report-generation jobs: check which identity runs them, how tenant scope is selected, and whether the database policy applies to that identity.
  • Caches: ensure cached report results are partitioned by tenant so one tenant cannot receive another tenant’s result.
  • Administrative and reporting identities: verify their permissions and whether any intentional cross-tenant access is separately controlled.

These are engineering checks for the application’s actual architecture, not a claim that the cited Microsoft pages provide a complete threat model for every reporting path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Authentication is not tenant row isolation

Authentication establishes who is making a request; tenant resolution determines the tenant context the application uses. Neither step alone forces every database query to obey that tenant boundary. Microsoft’s ASP.NET Core 10.0 authentication overview states that ASP.NET Core has no built-in multi-tenant authentication solution. Treat identity, tenant resolution, application filtering, and database enforcement as separate parts of the design.

Quick Recap

SaleBestseller No. 1
Database Security
Database Security
Used Book in Good Condition
$75.09
SaleBestseller No. 2
Bestseller No. 3
Bestseller No. 5
BookFactory Security Pass Down Log Book, Wire-O, 100 Pages
BookFactory Security Pass Down Log Book, Wire-O, 100 Pages
Made in USA - Proudly produced in Ohio by a Veteran-owned business
$22.99
Best Value
BookFactory Security Pass Down Log Book, Wire-O, 100 Pages
  • Made in USA - Proudly produced in Ohio by a Veteran-owned business
  • Comprehensive Coverage: This BookFactory log book includes essential fields such as post/shift, time of change, date, weather conditions, and a designated space for detailed notes. This ensures that all relevant information is captured and easily accessible.
  • Sturdy Cover: The trans-lux cover protects the log book from wear and tear, ensuring its longevity and maintaining the integrity of your recorded data.
  • Essential Security Tool: This log book is an indispensable tool for any organization that values security and accountability. It helps to prevent misunderstandings, improve communication, and ensure a smooth transition between shifts.
  • Wire-O with Trans-lux cover, 100 Pages, Dimensions 8.5" x 11" - (Security-Pass-Down) Reorder SKU: LOG-100-7CW-PP(Security-Pass-Down)

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.