0

Steps to reproduce:

  1. Create a WebSite project in Visual Studio.
  2. Add a reference to System.Data.Entity
  3. Add a "Web Page Razor v3", with following content:

@using System.Data.Entity;
@{
var db = Database.Open("WebPagesMovies");
//var selectCommand = "SELECT * FROM Movies";
//var searchTerm = "";
}
<!DOCTYPE html>
<html>
  <head>
    <title></title>
  </head>
  <body>

  </body>
</html>

My problem is, that the class Database is not recognized. The class is located in the system data entity namespace. If i do the same steps in a ASP .NET Web Application project, the reference is recognized. Because a website project has no csproj file, the references are placed in the web.config file. I see there following entry:

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

Does anybody get what i am missing here? Why can I not reference that namespace?

Diego Frehner
  • 2,396
  • 1
  • 28
  • 35
  • Have you seen [this](http://www.codeproject.com/Tips/256090/Add-namespaces-for-Razor-pages)? As an author states you have to modify View/Web.config file. – Maciej Los May 29 '16 at 21:33
  • Another solution, which refer to the same ways to resolve issue you'll find [here](http://stackoverflow.com/questions/3239006/how-do-i-import-a-namespace-in-razor-view-page) – Maciej Los May 29 '16 at 21:40
  • Did any of the comments or the answer help resolve your issue? – gmiley May 30 '16 at 00:03

1 Answers1

0

System.Data.Entity.Database is only available for Entity Framework 5.0 and above: https://msdn.microsoft.com/en-us/library/system.data.entity.database%28v=vs.113%29.aspx

You need to ensure you have the correct version referenced. You will also need to ensure that your project is targeting the proper version of .Net Framework. You will need, I believe, .Net Framework 4.5 for Entity Framework 5+ to work properly.

You can download Entity Framework here: https://msdn.microsoft.com/en-us/data/ee712906.aspx

gmiley
  • 6,531
  • 1
  • 13
  • 25