I am using a PluginManager which searches for dll Files and add them (and her functions) to my current application.
I also use Entity Framework to create a database and tables from objects, but I have to declare the objects for the database in the DatabaseContext class.
How can I save some objects from a plugin in this database?
I tried this:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
foreach( PluginDto plugin in BackendContext.Current.PluginManager._plugins) {
foreach(Type obj in plugin.plugin.getPluginDatabaseObjects())
{
Type typ = typeof(EntityTypeConfiguration<>).MakeGenericType(obj);
List<MethodInfo> l = modelBuilder.GetType().GetMethods().ToList<MethodInfo>();
MethodInfo m_Entitiy = modelBuilder.GetType().GetMethod("Entity").MakeGenericMethod(new Type[] { obj });
var configObj = m_Entitiy.Invoke(modelBuilder, null);
MethodInfo m_ToTable = configObj.GetType().GetMethod("ToTable", new Type[] { typeof(String) });
m_ToTable.Invoke(configObj, new object [] { obj.Name });
}
}
}
But get this exception:
An unhandled exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll
Additional information: The model backing the 'DatabaseContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).