Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing EntityFramework 4.1 namespace in MVC3 Razor View

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

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" />

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?

EDIT: 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).

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"/>

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"/>

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.

like image 289
DMC Avatar asked Dec 07 '25 06:12

DMC


1 Answers

Okay, figured it out through trial and error.

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" />
like image 165
DMC Avatar answered Dec 08 '25 22:12

DMC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!