EFUnitOfWorkFactory 初始化
我正在尝试初始化 EFUnitOfWorkFactory 对象上下文。
在 global.asax 中:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
ObjectFactory.Initialize(x =>
{
x.For<IUnitOfWorkFactory>().Use<EFUnitOfWorkFactory>();
x.For(typeof(IRepository<>)).Use(typeof(EFRepository<>));
}
);
EFUnitOfWorkFactory.SetObjectContext(() => new MyEntities());
}
在生成的对象上下文中,我有:
public partial class MyEntities : ObjectContext
{
.....
.....
}
当我在 EFUnitOfWorkFactory.SetObjectContext(() => new MyEntities()); 中执行 Web 应用程序时出现异常:
Compiler Error Message: CS0012: The type 'System.Data.Objects.ObjectContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
我添加了 System .Data.Entity 到我的网络应用程序两次并重建,但我仍然收到此消息。另外,gobal.asax 中的这一行有时会标有红色下划线。
有谁知道如何解决这个问题?
I am trying to initialize the EFUnitOfWorkFactory object context.
In global.asax:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
ObjectFactory.Initialize(x =>
{
x.For<IUnitOfWorkFactory>().Use<EFUnitOfWorkFactory>();
x.For(typeof(IRepository<>)).Use(typeof(EFRepository<>));
}
);
EFUnitOfWorkFactory.SetObjectContext(() => new MyEntities());
}
In the generated Object context I have:
public partial class MyEntities : ObjectContext
{
.....
.....
}
I get an exception when I execute the web application in EFUnitOfWorkFactory.SetObjectContext(() => new MyEntities());
:
Compiler Error Message: CS0012: The type 'System.Data.Objects.ObjectContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I added System.Data.Entity to my web application twice and rebuild but I still get this message. In addition, this line in the gobal.asax smetimes marked with red underline.
Does anyone knows how to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定 Web 应用程序或网站中引用的程序集中有来自 .NET 4.0 的 System.Data.Entity.dll 吗?它也应该出现在 web.config 中:
Are you sure that you have System.Data.Entity.dll from .NET 4.0 in your referenced assemblies in the web application or web site? It should also appear in web.config: