Currently (the latest official EF Core v1.1.2) there is no public alternative. It is planned to set up Lifetime Hooks , but according to the EF Core Roadmap they are postponed and will not be available in the upcoming version v2.0.
, EF Core /, EF Core
API Core Entity Framework . API .
Microsoft.EntityFrameworkCore.ChangeTracking.Internal
, , ILocalViewListener
,
void RegisterView(Action<InternalEntityEntry, EntityState> viewAction)
viewAction
, , , , , ..
, DbContext
ILocalViewListener
:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
public class MyDbContext : DbContext
{
public MyDbContext()
{
this.GetService<ILocalViewListener>()?.RegisterView(OnStateManagerChanged);
}
void OnStateManagerChanged(InternalEntityEntry entry, EntityState previousState)
{
if (previousState == EntityState.Detached && entry.EntityState == EntityState.Unchanged)
{
var entity = entry.Entity;
}
}
}
InternalEntityEntry.ToEntityEntry()
EntityEntry
( DbContext.Entry
ChangeTracker.Entries
), , InternalEntityEntry
.
EF Core v1.1.2.