Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the combination of ADO.NET Entity Framework and ASP.MVC wrong by any chance?

I have one solution with three projects.

  1. DomainModel (C# Library with ADO.NET Entity Framework)
  2. DomainModelTest (Unit Testing for Business Logic)
  3. WebApp (Using DomainModel)

For some reason, I cannot even bring the view if I pass any of the objects in the DomainModel, not even simple. I get the error below:

Any ideas?

Compiler Error Message: CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Source Error:

Line 146: Line 147:
[System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()] Line 148: public class views_home_index_aspx : System.Web.Mvc.ViewPage, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler { Line 149:
Line 150: private static bool @__initialized;

I thought this might be helpful, the actual error comes up on the Default.aspx file in the line pointed below:

public partial class _Default : Page
{
    public void Page_Load(object sender, System.EventArgs e)
    {
        // Change the current path so that the Routing handler can correctly interpret
        // the request, then restore the original path so that the OutputCache module
        // can correctly process the response (if caching is enabled).

        string originalPath = Request.Path;
        HttpContext.Current.RewritePath(Request.ApplicationPath, false);
        IHttpHandler httpHandler = new MvcHttpHandler();
        httpHandler.ProcessRequest(HttpContext.Current); //**HERE**
        HttpContext.Current.RewritePath(originalPath, false);
    }
}
like image 342
Geo Avatar asked Oct 01 '09 02:10

Geo


People also ask

Can ADO.NET be used with MVC?

MVC (Model View Controller) is a web application design pattern that is widely used in application development. Here, we are creating an MVC application that connects to the SQL Server with the help of ADO.NET framework. This application contains a Model, a View and a Controller file.

Can we use Entity Framework and ADO.NET together?

The entity framework is a powerful framework that handles the database services that generate the mechanism of basic SQL queries, we can use these both in one project so that the entity framework performs the CRUD operation and the ADO.net performs the reporting and is used to operates the bulk of SQL data operations.

Is Entity Framework and MVC the same?

MVC is framework mainly concentrates on how you deliver a webpage from server to client. Entity framework is an object relational mapper which helps you to abstract different types of databases (MSSQL,MySQL etc) and helps querying objects instead of having sql strings in our project.

What is ADO.NET Entity Framework in MVC?

The ADO.NET Entity Framework is an ORM (Object Relational Mapping) tool and is Microsoft's main data access strategy moving forward. Microsoft released version 1 with Visual Studio 2008 SP1 with the . NET Framework 3.5 SP1.


2 Answers

Try adding the reference in your web.config, in the < assemblies > section.

like image 64
Abram Simon Avatar answered Oct 16 '22 22:10

Abram Simon


In web.config Add this

<configuration>
  <system.web>
    <compilation>
      <assemblies>
        <add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>
like image 38
Saiful Avatar answered Oct 16 '22 21:10

Saiful