I am trying to implement a global filtering for some entities that are inheriting from a BaseEntity. And I want this filtering to be somehow automatic. So what I am doing is: I am getting all the inheriting classes:
IEnumerable<BaseEntity> exporters = typeof(BaseEntity)
.Assembly.GetTypes()
.Where(t => t.IsSubclassOf(typeof(BaseEntity)) && !t.IsAbstract)
.Select(t => (BaseEntity)Activator.CreateInstance(t));
List<BaseEntity> listEntities = exporters.ToList<BaseEntity>();
Until here it is working I am getting all the sub-classes. Now I want to apply some filter on those classes, but I can't find a way to achieve that. Based on the below code:
builder.Entity<Might need some Reflection here to get the class>().HasQueryFilter(p => !p.IsDeleted);
Not so sure if it something doable or should I go on the manual way?
Aucun commentaire:
Enregistrer un commentaire