2009-10-01 74 views
15

我有三个项目的解决方案。ADO.NET实体框架和ASP.MVC的结合是错误的吗?

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

出于某种原因,我甚至不能带来该视图是否通过DomainModel中的任何对象,甚至不是很简单。我得到以下错误:

任何想法?

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;

我想这可能是有用的,实际的错误出现在行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); 
    } 
} 
+0

您是否在Web项目中添加了对System.Data.Entity的引用? – JasonTrue 2009-10-01 02:34:28

+0

@Jason。是的,我做到了。我删除它,重新添加它,甚至检查版本,也尝试使用homecontroller中的语句。我甚至认为这是我的观点,所以我删除它们并重新创建它们。当他们没有引用由ado.net创建的对象enti fram都是好的,只要我尝试用户或任何其他对象,就会发生编译错误。谢谢。 – Geo 2009-10-01 02:38:35

+0

在这里,我找到了答案如何解决编译问题 [http://stackoverflow.com/a/5129828/305197][1] [1]:http://stackoverflow.com/ a/5129828/305197 – 2012-11-20 22:30:48

回答

27

尝试添加在你的web.config参考,在<程序集>部分。

+0

谢谢!我一个人花了大约1.5个小时。这是一个已知的错误?不管怎么说,还是要谢谢你。 – Geo 2009-10-01 02:57:49

+1

我不认为我会把它称为一个bug ...包括项目中的参考是第一步。如果你想在控制器中使用它,你必须有一个'使用'语句,如果你想在视图中使用它,它需要在web.config中或在视图标记中声明导入。我几次抨击我的头,但我现在吸取了教训:) – 2009-10-01 13:02:03

+1

@AJ,我非常认为这是一个错误。通常,当我添加对Web应用程序的引用时,我只需添加一次。 – ProfK 2010-07-11 08:12:58

15

在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> 
1

您还可以添加一个空的ADO.NET实体数据模型到您的Web项目,然后将其删除。它将为您添加必要的参考。