I'm using entity framework and in my context I've done some stuff like:
public override int SaveChanges()
{
foreach (var entry in ChangeTracker.Entries())
{
if (entry.Entity is Base entity)
{
if (entry.State == EntityState.Added)
{
entity.Created = DateTime.UtcNow;
entity.Modified = DateTime.UtcNow;
}
else if (entry.State == EntityState.Modified)
{
entity.Modified = DateTime.UtcNow;
}
}
}
return base.SaveChanges();
}
Where Base is:
public int Id { get; set; }
public DateTime? Created { get; set; }
public DateTime? Modified { get; set; }
public bool IsDeleted { get; set; }
Now what I'm trying to do is when I load properties using my context like:
_context.MyEntities.AsEnumerable(something);
I want it to select all entities that have the IsDeleted
property set to false. Is it possible to do this in the DbContext
like I'm making changes by overriding SaveChanges()
I can see that there is a method to override, but not sure how to go about it:
public override DbSet<TEntity> Set<TEntity>()
{
return base.Set<TEntity>();
}