5

I'm creating my first asp.net MVC website(the version 3).

I'm using Entity Framework to get data from my database, so for now, I've a movies list in my database.

I'm trying to do a page which display the list of these movies.

So, the controller seems to be OK, it returns a View(IEnumerable).

In the view, I specified the type of my model:

@model IEnumerable

Movie is a class generated with a T4 template from my edmx, so it is heriting from EntityObject.

Now, when I try to display my page, I'm getting an error, indicating me that I've to import System.Data.Entity:

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0012: Le type 'System.Data.Objects.DataClasses.EntityObject' est défini dans un assembly qui n'est pas référencé. Vous devez ajouter une référence à l'assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Source Error:

Line 27: Line 28: Line 29:
public class _Page_Views_Movie_List_cshtml : System.Web.Mvc.WebViewPage> { Line 30: Line 31: #line hidden

Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\93402ec0\8f8e48f4\App_Web_list.cshtml.9612c299.pwpwk-k5.0.cs Line: 29

But, I've referenced this dll in my project and i've the corresponding using in my controller.

I tried to put this using in the cshtml: @using System.Data.Entity but it doesn't compile with(cannot find Entity in System.Data)

So what should I do?

all my projects are .Net 4(not the client profile)

2
  • which dll did you ref - System.Data or System.Data.Entity? Commented May 6, 2011 at 17:21
  • For the love of all programming gods, uninstall your .NET Framework language packs for English exception messages. Commented Jun 25, 2012 at 11:50

4 Answers 4

3

add the following line to your web.config

<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
Sign up to request clarification or add additional context in comments.

2 Comments

I tried: <system.web> <compilation> <assemblies> <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> </assemblies> </compilation> </system.web> but it doesn't change anything
Adding this reference allows you to specify @using System.Data.Entity in your view, which allows you to reference entities
1

two things - 1. change your model definition as was mentioned by Muhammed - its more standard that way as well 2. include a reference to: C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Data.Entity.dll

OR use the POCO Entity.Net templates in whatever projects your entities are in to free you from the dependency on that library in your mvc project.

Comments

1

For Asp.Net Mvc 2 And 3

 <compilation debug="true" targetFramework="4.0" >
 <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  ...
 </assemblies>

For ASP.NET MVC 4 (.NET4.5) change from

<system.web>
     <compilation debug="true" targetFramework="4.0" />

To

 <system.web>
   <compilation debug="true" targetFramework="4.0" >
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      </assemblies>
    </compilation>

Comments

0

Please try specifying typed enumeration like

@model IEnumerable<MyEntityObjectType>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.