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

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-12 12:51:22

问题


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);
    }
}

回答1:


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




回答2:


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>



回答3:


You can also add an empty ADO.NET Entity Data Model to your web-project, and then delete it. It will add the necessary references for you.



来源:https://stackoverflow.com/questions/1501616/is-the-combination-of-ado-net-entity-framework-and-asp-mvc-wrong-by-any-chance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!