在MVC3的Razor视图引用的EntityFramework 4.1命名空间 [英] Referencing EntityFramework 4.1 namespace in MVC3 Razor View

查看:165
本文介绍了在MVC3的Razor视图引用的EntityFramework 4.1命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想引用我的MVC3项目的共享视图内的System.Data.Entity.Validation(EF 4.1版本)命名空间。我已经能够引用使用其他外部库:

I am trying to reference the System.Data.Entity.Validation (EF 4.1 version) namespace inside of a shared View in my MVC3 project. I've been able to reference other external libraries using:

@using Example.Namespace

我不能,但是,得到当它涉及到的是新的4.1的EntityFramework的零件库工作同样的事情。我曾尝试添加下面的视图文件夹中的web.config文件:

I cannot, however, get the same thing to work when it comes to libraries that are part of the new 4.1 EntityFramework. I have tried adding the following to the web.config within the Views folder:

<add namespace="System.Data.Entity.Validation, EntityFramework, Version=4.1.10715.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />

我觉得我是在正确的轨道上,因为现在的智能感知是炸毁对于曾经工作等外部命名空间。有人可以帮我找出在web.config条目应该看起来完全像什么这个?

I think I am on the right track, because now the intellisense is blowing up for other external namespaces that used to work. Can someone help me figure out exactly what the web.config entry should look like for this?

编辑:要清楚,我想在我看来,其中,因为据我所知,是的EntityFramework 4.1 DLL的一部分,最终使用DbEntityValidationException。我下面这个职位,这似乎暗示我需要的名称空间声明添加到信息(http://stackoverflow.com/questions/3239006/how-to-import-a-namespace-in-razor-view-page)视图中的web.config文件中的部分(不是项目WEB.CONFIG)。

to be clear, I am trying to ultimately use DbEntityValidationException in my view, which, as far as I know, is part of the EntityFramework 4.1 DLL. I am following information in this post (http://stackoverflow.com/questions/3239006/how-to-import-a-namespace-in-razor-view-page) which seems to suggest I need to add the namespace declaration to the section of the web.config file within Views (NOT THE PROJECT WEB.CONFIG).

我仍然通过这个工作,我已经发现,添加组件到视图的web.config也对System.Web /编译/组件节作品,它要么打破了所有的智能感知,或给我的命名空间的一部分我想要。比如,我说:

I am still working through this and I have found that adding assemblies to the system.web/compilation/assemblies section of the View's web.config also 'works' in that it either breaks all intellisense or gives me part of the namespace I want. For example, I added:

<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

这让我可以在我看来键入System.Data.Entity的,但没有后出现在智能感知。如果我将其更改为:

That allows me to type System.Data.Entity in my view, but nothing appears in Intellisense after that. If I change it to:

<add assembly="System.Data.Entity.Validation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

在我关闭并重新打开我的项目,在我看来,一切的智能感知休息,我看到以下错误:ASP.NET运行时错误:无法加载文件或程序'System.Data.Entity.Validation版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089或它的一个依赖。该系统找不到指定的文件。

After I close and re-open my project, the intellisense breaks on everything in my view and I see the following error: ASP.NET runtime error: Could not load file or assembly 'System.Data.Entity.Validation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

推荐答案

好了,想通了,通过试验和错误。

Okay, figured it out through trial and error.

事实证明,你必须有在的System.Web /编译/组件内的以下条目或者您的根web.config,或查看的web.config:

As it turns out, you must have the following entry in either your root web.config, or the View's web.config inside of system.web/compilation/assemblies:

<add assembly="EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

这篇关于在MVC3的Razor视图引用的EntityFramework 4.1命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆