0

我已升级到 Entity Framework 4.3 并收到以下错误:

   [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 中工作。我尝试从模型中排除所有内容并引入内容,直到出现问题 - 但一切正常。

谢谢!

4

2 回答 2

1

已修复 - 关联双方的配置是问题的原因。当它发布时,我们将移至 EF 5。

我团队中的一个人拥有 VS Ultimate,因此能够使用 Intellitrace 查看 EF 内部发生的情况。事实证明,导航属性之一在一种配置中定义为可选,而在另一种配置中定义为必需。该模型太大,无法以任何其他方式追踪到这一点。

Visual Studio 似乎按依赖顺序构建模型,而 TFS/MSBUILD 似乎按配置类按字母顺序构建模型。这种差异是它在我们的开发机器上工作但在 TFS 构建上不起作用的原因。

您会认为到 4.3 版他们可能已经将一些调试/异常信息放入框架中,或者至少以某种方式验证模型!

于 2012-05-04T08:38:24.970 回答
0

这是一个应该在 Entity Framework 5 中修复的错误。如果您无法迁移到 EF5,您可以通过在关联方的两个配置中指定导航属性来解决此问题。

于 2012-05-02T20:57:56.327 回答