在MVC应用程序中从web形式转换为DbContext到ObjectContext

时间:2014-05-13 14:09:23

标签: webforms asp.net-mvc-5 entity-framework-6 dbcontext objectcontext

我有一个使用EF 6.1的MVC5应用程序,基本表单非常好用。需要开发一些复杂的形式,因此webforms似乎是更好的选择。遵循有关将DbContext转换为ObjectContext的所有建议,以便使用EntityDataSource进行数据库通信,但只是获取'无法将System.Data.Entity.Core.Objects.ObjectContext类型隐式转换为System.Data.Objects。尽管已更新到应该解决此问题的最新版本,但ObjectContext' 错误。

protected void EntityDataSource_ContextCreating(object sender, EntityDataSourceContextCreatingEventArgs e) 
{ 
    var db = new myDbContext(); 
    e.Context = (db as IObjectContextAdapter).ObjectContext; 
    //also tried e.Context = ((IObjectContextAdapter)db).ObjectContext;
}

非常感谢任何关于让webforms与MVC5一起运行的建议,特别是在为插入正确设置连接方面。

0 个答案:

没有答案