【发布时间】:2016-09-05 13:07:17
【问题描述】:
我正在使用 PluginManager 搜索 dll 文件并将它们(和她的函数)添加到我当前的应用程序中。
我也使用实体框架从对象创建数据库和表,但我必须在 DatabaseContext 类中为数据库声明对象。
如何将插件中的一些对象保存到此数据库中?
我试过这个:
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 });
}
}
}
但是得到这个异常:
EntityFramework.dll 中出现“System.InvalidOperationException”类型的未处理异常
附加信息:支持“DatabaseContext”上下文的模型自数据库创建以来已更改。考虑使用 Code First 迁移来更新数据库 (http://go.microsoft.com/fwlink/?LinkId=238269)。
【问题讨论】:
标签: c# entity-framework dll plugins