Subscription to ChangeTracker.StateChanged events
See original GitHub issueCan you please advise how to subscribe to ChangeTracker.StateChanged events but keep reverse engineering automatic-generated DbContext file intact?
This works in the original file:
public partial class MyContext : DbContext
{
public MyContext(DbContextOptions<MyContext> options)
: base(options)
{
ChangeTracker.StateChanged += OnEntityStateChanged;
}
This doesn’t work in a separate file:
public partial class MyContext
{
public MyContext() : base()
{
ChangeTracker.StateChanged += OnEntityStateChanged;
}
Or maybe you can advise a way how to subscribe to events outside from default DbContext constructor. So little information how to use it, and most SO posts suggest to put subscription into default constructor.
Issue Analytics
- State:
- Created 6 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
ChangeTracker.StateChanged Event
An event fired when an entity that is tracked by the associated DbContext has moved from one EntityState to another.
Read more >ChangeTracker.StateChanged of DbContext gets triggered ...
I found that ChangeTracker.StateChanged is triggered when _dbContext.Entry(student) is called. Then it doesn't get triggered again when ...
Read more >Change Detection and Notifications - EF Core
EF Core fires the ChangeTracker.Tracked event when an entity is tracked for the first time. Future entity state changes result in ChangeTracker.
Read more >How to Use .NET Evens provided by EF Core
ChangeTracker.StateChanged – This event is raised when an operation is performed on an entity, that caused entity to change its EntityState ...
Read more >5 Ways to Trigger Actions Before or After Save in EF
You can subscribe to these events and provide a delegate that handles them. For example, you can use the StateChanged event to check...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Then you can use the t4 template to modify the constructor
Cool, let me know if you need additional advice