jeudi 21 juin 2018

Casting a reflected object to another type with a GenericTypeArgument during runtime

Situation:

In an api controller I get a string of a type and need to get a working Iqueryable from this.

I can get something from this through reflection on the dbcontext, which has all the objects I would need as DbSet<Type>, which I then do AsQueryable() on.

Problem is that the only way to get the Correct DbSet from the context is through reflection. But this only return an object of type Object.

I don't know any way to cast this object back to it's DbSet<Type> during runtime and I was wondering if someone else knew of it.





Aucun commentaire:

Enregistrer un commentaire