Skip to content
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

Global query filter not parameterised #33765

Closed
TheJackGower opened this issue May 20, 2024 · 2 comments
Closed

Global query filter not parameterised #33765

TheJackGower opened this issue May 20, 2024 · 2 comments

Comments

@TheJackGower
Copy link

Ask a question

We've been following https://learn.microsoft.com/en-us/ef/core/querying/filters to implement a global query filter to support our multi-tenancy setup. Our current 'hand-crafted' scoping only handles the main entity, and not any joined entities/sub-collections.

The current TenantId is passed down the data context via parameter, and then placed in the query filter like so:

modelBuilder.Entity<ApprovalGroup>()
    .HasQueryFilter(x => x.TenantId == tenantId)
    .HasMany(t => t.ApprovalChainNodeApprovalGroups)
    .WithOne(t => t.ApprovalGroup)
    .HasForeignKey(t => t.ApprovalGroupId)
    .OnDelete(DeleteBehavior.NoAction);

All seemed fine however on inspecting the sql generated we noticed the value wasn't parameterised:

image

Is this a restriction on using the query filter or is it due do the TenantId being provided as a parameter and therefore not being class-level? Is there a possible workaround to avoid the need for generating separate query plans across tenants?

Thanks :)

Include provider and version information

EF Core version: 8.0.5
Database provider: Azure SQL Server
Target framework: .NET8
Operating system: Windows 11
IDE: Visual Studio 2022 17.9

@cincuranet
Copy link
Contributor

This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

@cincuranet
Copy link
Contributor

I'm closing because of inactivity. Will open when required information is provided.

@cincuranet cincuranet closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants