I have a .dll file that I want to import into my projects and below is a class that belongs to the .dll
I'm able to get the name of the DbContext of the solution but in the next line when I try to get type of it, it is null. It's understandable as the desired type does not exist in that solution. but is it possible to create the type and instance in this case?
any help is very appreciated, thanks!
static class EntityBase
{
public static DbContext MyCreateNewDbContextInstance()
{
string myDbContextName = Assembly.GetEntryAssembly().DefinedTypes
.Where(t => typeof(DbContext).IsAssignableFrom(t)).ToList().First().FullName;
Type type = Type.GetType(myDbContextName);
var context = Activator.CreateInstance(type, false);
return (DbContext)context;
}
}
Aucun commentaire:
Enregistrer un commentaire