ADO.NET实体框架和ASP.MVC的组合是否有任何错误?

Geo*_*Geo 15 c# asp.net-mvc entity-framework

我有三个项目的解决方案.

  1. DomainModel(带有ADO.NET实体框架的C#库)
  2. DomainModelTest(业务逻辑的单元测试)
  3. WebApp(使用DomainModel)

出于某种原因,如果我传递DomainModel中的任何对象,我甚至无法带来视图,甚至不是简单的.我收到以下错误:

有任何想法吗?

编译器错误消息:CS0012:类型'System.Data.Objects.DataClasses.EntityObject'在未引用的程序集中定义.您必须添加对程序集'System.Data.Entity,Version = 3.5.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的引用.

来源错误:

第146行:第147行:
[System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]第148行:公共类views_home_index_aspx:System.Web.Mvc.ViewPage,System.Web.SessionState.IRequiresSessionState,System.Web.IHttpHandler {第149行:
行150:private static bool @__initialized;

我认为这可能会有所帮助,实际错误出现在下面指向的行中的Default.aspx文件中:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

Abr*_*mon 29

尝试在<assemblies>部分的web.config中添加引用.


Sai*_*ful 16

在web.config中添加此项

<configuration>
  <system.web>
    <compilation>
      <assemblies>
        <add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)