Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 views
in Technique[技术] by (71.8m points)

asp.net mvc 3 - Could not load file or assembly 'System.Data.Entity

I am working within a Solution (a jokes website). The Solution has 2 Projects:

  1. Model (C# Class Library)
  2. MVC 3 Empty Application

I am trying to get my view to list the Jokes in the Database, but I get the following error:

Could not load file or assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified

As you can see from the Error message, I have already added the System.Data.Entity to the web.config of the MVC 3 application.

No matter what I do, I seem to be unable to fix the error! I have added using statements for the Entity class, to the HomeController and the Index.cshtml.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To use an external Entity Framework model (embed in a DLL for example) with ASP.NET MVC 3 you must :

  1. Add the following reference to your MVC project : System.Data.Entity (Version 4.0.0.0, Runtime v4.0.30319)
  2. Add the following line in your web.config

...

< compilation debug="true" targetFramework="4.0">

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...