I have a instance of DbContext, that have properties is the DbSet<"EntityName">. I have used the reflection to get all the instance of each DbSet<"EntityName">, but i can not use it, cause of i cant not cast it in to the DbSet<"EntityName">.
var types = _dbContext.GetType().GetProperty();
foreach(var type in types){
var dbSetValue = type.GetValue(_dbContext, null);
var entities = dbSetValue.ToList(); // error cause of i cant not cast it.
}
So in this case, i want to cast the dbSetValue
to its type (DbSet..), The problem is the DbSet have the generic, that is can not cast. Is it posible?
Aucun commentaire:
Enregistrer un commentaire