question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make parameterization of global query filters more obvious

See original GitHub issue

From below:

Notes from triage: the current design of query filters uses the DbContext as the anchor from which filter parameters are read. This works well in many cases, but has a couple of limitations:

  • People don’t get it. That is, many times we see code that attempts to hard-code the filter value into the model and then re-build the model for each context instance. This can be made to work, but only with terrible perf characteristics, which makes it a pit-of-failure.
  • It requires a stronger coupling of the DbContext type to the entity types being used than is ideal–essentially the issue reported above.

Based on this, it might be worth designing and implementing query filters where the filter parameter is obtained in a different way–such as through a defined callback. This would be easier for many to understand and would not have a strong coupling to the context.


Original issue:

For a enterprise level application you cant define an entire data model directly on the DbContext, you use IEntityTypeConfiguration<TEntity> to seperate configuration away from OnModelCreating method.

When it comes to HasQueryFilter that uses expressions with dependencies to scoped members there is no such mechanics. It needs to be defined directly on the DbContext. This just wont cut it for a large Enterprise level application.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
joshcomleycommented, Jan 13, 2020

@AndersMalmgren this won’t apply the query filters to any .Include(..) you use. Just want you to be aware of the security risk of doing that; your API may expose unwanted data via expands.

0reactions
AndersMalmgrencommented, Jan 13, 2020

No, If any entity has a relation to another entity that is under restriction that entity also needs to have filters. Thats ok in our case. Child and parents always have same restrictions.

We dont use Include but we project all queries to DTOs that might include children

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make parameterization of global query filters more obvious
Notes from triage: the current design of query filters uses the DbContext as the anchor from which filter parameters are read. This works...
Read more >
entity framework core - Pass a parameter to global query filter
With new ef.core global query filters, is it possible to pass a dynamic parameter to it? I want all queries to be filtered...
Read more >
Global Query Filters for Interfaces | You've Been Haacked
This post describes how to apply an Entity Framework Core Global Query filter on all entity types that implement an interface using a ......
Read more >
Advanced Performance Topics
The poolSize parameter of AddDbContextPool sets the maximum number ... into account by queries (see Global Query Filters for more details).
Read more >
Efficient Querying - EF Core
If a query filters by an expression over a column (e.g. price / 2 ), a simple index cannot be used. However, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found