Skip to content

Why filters should come last in the model creation? #170

@julealgon

Description

@julealgon

Description

The documentation on dynamic filters mention this:

Filters should always follow any other model configuration - including the call to the base.OnModelCreating() method. It is best to make the filter definitions the final step of OnModelCreating() to make sure that they are not in effect until the entire model is fully configured.

However, it is not clear to me what exactly are the consequences of having the filters defined earlier in the method.

Currently, we have an application with a very complex multi-tenant database structure and we are experiencing StackOverflowExceptions in a few cases randomly. I noticed that our own dbcontext does have the dynamic filters for multi-tenancy and soft deletion at the very beginning of OnModelCreating , (which goes against the recommendation) and wondered if this could have anything to do with the huge stack traces we are getting from EF. In some cases, plan compilation goes crazy into tree recursion for 4000+ calls, so something must be generating incredibly deep ASTs for it to visit.

Could you elaborate (and perhaps update the docs) on what exactly are the problems or behaviors that could come from having the filters not at the end of the method?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions