2012-05-02 61 views
0

我已經升級到實體框架4.3,並得到以下錯誤:實體框架拋出NullReferenceException異常在ValidateConsitency

[NullReferenceException: Object reference not set to an instance of an object.] 
    System.Data.Entity.ModelConfiguration.Configuration.Properties.Navigation.NavigationPropertyConfiguration.ValidateConsistency(NavigationPropertyConfiguration navigationPropertyConfiguration) +588 
    System.Data.Entity.ModelConfiguration.Configuration.Properties.Navigation.NavigationPropertyConfiguration.Configure(EdmNavigationProperty navigationProperty, EdmModel model, EntityTypeConfiguration entityTypeConfiguration) +122 
    System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigureAssociations(EdmEntityType entityType, EdmModel model) +160 
    System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EdmEntityType entityType, EdmModel model) +102 
    System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntities(EdmModel model) +95 
    System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) +112 
    System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +58 
    System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +62 
    System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +117 
    System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +452 
    System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes() +55 
    System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext() +25 
    Namespace.Test.Start() in c:\Builds\6\Test\DevDeployed\Sources\Namespace.Test.Kernel\Loader.cs:97 
    MvcApplication.Application_Start() in c:\Builds\6\Test\DevDeployed\Sources\Namespace.Test.Kernel\Web\Global.asax.cs:48 

如果我在Visual Studio中創建應用程序的工作,但自動部署網站(通過TFS)給出了這樣的錯誤(就像在命令行中使用MSBUILD一樣)。

似乎沒有任何方法可以得到體面的錯誤信息,所以我在黑暗中導致問題的原因。我不認爲這是一個映射問題,因爲我可以讓它在VS中工作。我試圖排除模型中的所有內容,並介紹一些事情,直到問題出現 - 但一切正常。

謝謝!

+0

構建發生在哪裏?如果它在另一臺服務器上,那麼是否需要在那裏安裝缺少的更新? – pantelif

+0

它發生在另一臺服務器上。實體框架DLL是從解決方案中引用並保存在解決方案的根目錄中 - 因此沒有需要更新機器本身。 – SturmUndDrang

回答

0

這是一個應該在Entity Framework 5中修復的錯誤。如果您不能移動到EF5,您可以通過在關聯端的兩種配置中指定導航屬性來解決這個問題。

1

修復它 - 關聯兩邊的配置是問題的原因。 EF 5發佈後我們將轉移到EF 5。

我的團隊中有一個人擁有VS Ultimate,所以能夠使用intellitrace來查看EF內部發生了什麼。事實證明,其中一個導航屬性在一個配置中被定義爲可選,在另一個配置中被定義爲必需。該模型太大而無法以任何其他方式進行跟蹤。

Visual Studio似乎以依賴順序構造模型,而TFS/MSBUILD似乎按照配置類的字母順序構造它。這種差異就是爲什麼它在我們的開發機器上工作,而不是在TFS版本上。

你可能會認爲在4.3版本中他們可能會在框架中加入一些調試/異常信息,或者至少是某種方式來驗證模型!

相關問題