开发者

ASP.Net MVC 3 & System.Data.Entity?

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.NE开发者_StackOverflow中文版T 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)


add the following line to your web.config

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


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.


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>


Please try specifying typed enumeration like

@model IEnumerable<MyEntityObjectType>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜