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

When to trigger IMaterializationInterceptor if materialization is not from a query? #33614

Closed
Li7ye opened this issue Apr 26, 2024 · 2 comments
Closed

Comments

@Li7ye
Copy link

Li7ye commented Apr 26, 2024

From documentation : The IMaterializationInterceptor supports interception before and after an entity instance is created, and before and after properties of that instance are initialized.

In most case, the interceptor is triggered from query. But there is a property QueryTrackingBehavior? QueryTrackingBehavior in MaterializationInterceptionData. The comment say if it is null, this materialization is not from a query.

As far as I know, when use InMemeory or Cosmos provider with model data seeding and call dbContext.Database.EnsureCreated() will trigger IMaterializationInterceptor. And, call entityEntry.GetDatabaseValues().ToObject() method as well.

Could you please help to summarize the all scenarios of triggering IMaterializationInterceptor for the materialization is not from query?

EF Core version: 8.0.0
Target framework: .NET 8.0
Operating system: Windows
IDE: (Visual Studio 2022)

@ajcvickers
Copy link
Member

@Li7ye This happens when the entity instance is created by the DbContext outside of any particular query. For example, EF may create instances of join entities when attaching either end of a many-to-many relationship. Similarly, creating new instances from data in the change tracker is another place. I don't have the full list of possibilities available off the top of my head, and new scenarios are likely to be added in the future.

@Li7ye
Copy link
Author

Li7ye commented May 6, 2024

Noted and thanks.

@Li7ye Li7ye closed this as completed May 6, 2024
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
@ajcvickers ajcvickers removed their assignment May 6, 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

3 participants