2009-10-01 45 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項目,然後將其刪除。它將爲您添加必要的參考。