我已升级到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中工作。我试图从模型中排除所有内容并引入问题直到问题出现 - 但一切正常。
谢谢!
答案 0 :(得分:1)
修复了 - 关联两边的配置是导致问题的原因。我们将在发布后转向EF 5。
我团队中的一个人拥有VS Ultimate,所以能够使用intellitrace来查看EF内部的情况。事实证明,其中一个导航属性在一个配置中定义为Optional,在另一个配置中定义为Required。这个模型太大了,无法以任何其他方式跟踪它。
Visual Studio似乎按依赖顺序构建模型,而TFS / MSBUILD似乎按配置类按字母顺序构造它。这种差异是它在我们的开发机器上工作但不在TFS构建上工作的原因。
你认为在版本4.3中他们可能会在框架中放入一些调试/异常信息,或者至少是一些验证模型的方法!
答案 1 :(得分:0)
这是一个应该在Entity Framework 5中修复的错误。如果您无法移动到EF5,您可以通过在关联方的两个配置中指定导航属性来解决此问题。