To make life easier for some of our developers, I want to create two DbSet<> for one database entity/table. Here's an example:
public class User
{
public int Id { get; set; }
public DateTime Deleted { get; set; }
}
public class UserContext : DbContext
{
public DbSet<User> DeletedUsers { get; set; }
public DbSet<User> ActiveUsers { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//for ActiveUsers
modelBuilder.Entity<User>().HasQueryFilter(e => e.Deleted == null);
//for DeletedUsers
modelBuilder.Entity<User>().HasQueryFilter(e => e.Deleted != null);
}
}
How can I make my two DbSet<> differentiate between these two? I want to be able to say dbContext.DeletedUsers.Where(x => x.Id == .....) instead of having to say dbContext.Users.Where(x => x.Deleted != null && x.Id == ......) all the same, as people might not remember that they're dealing with deleted users (or counterwise).