mercredi 3 avril 2019

Invoking method "Find" on unknown DbSet throws: "Object does not match target."

I want to run method "Find" on unknown DbSet. And find a record which name is "string". I do it this way:

PropertyInfo classInfo = db.GetType().GetProperty(myClass);
Type classObject = prop.GetValue(db).GetType();
var classObjectMethod = classObject.GetMethods().Last(x=>x.Name=="Find");
var record = classObjectMethod.Invoke(classObject, new object[] { new object[] {"string"} });

It throws "System.Reflection.TargetException: 'Object does not match target type.'" and I don't know why. How can I make this work?





Aucun commentaire:

Enregistrer un commentaire