【发布时间】:2011-11-20 22:34:47
【问题描述】:
当涉及到 WCF\EF 时,我目前正在使用由另一个开发人员创建的实体\表来开发一个项目。我通常很快就能赶上新事物,并且我对如何使用数据上下文在应用程序中完成工作有一些基本的了解。我唯一的问题是其他开发人员创建的上下文似乎不起作用,我不确定问题出在模型、映射还是表上。
这是该项目的基本前提。开发人员首先创建了数据库,然后将带有这些对象的 EF 映射的 POCO 对象创建到表中。他这样做是为了确保以后使用更新的列\表轻松升级。在创建模型时,通过覆盖 OnModelCreating 事件并将映射添加到每个对象的模型构建器,替换映射而不是 EF 的映射。那么接下来似乎发生的事情就是 NullReferenceException:
at System.Data.Entity.ModelConfiguration.Configuration.Properties.Navigation.NavigationPropertyConfiguration.ValidateConsistency(NavigationPropertyConfiguration navigationPropertyConfiguration)
at System.Data.Entity.ModelConfiguration.Configuration.Properties.Navigation.NavigationPropertyConfiguration.Configure(EdmNavigationProperty navigationProperty, EdmModel model, EntityTypeConfiguration entityTypeConfiguration)
at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigureAssociations(EdmEntityType entityType, EdmModel model)
at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EdmEntityType entityType, EdmModel model)
at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntities(EdmModel model)
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
我的主要问题是,我似乎无法通过搜索找到任何可以导致我找到此问题的原因的信息,因为我似乎无法找到其他人在此特定方法中遇到此问题。我会包含映射\POCOs\usage 的代码 sn-ps,但我在这个项目的保密协议下,我不知道扩展到什么程度。我的主要问题是,如果有人能告诉我应该在哪个区域寻找导致此问题的原因... POCO 设置、映射设置或表格设置?任何帮助将不胜感激!我自己多次查看了所有代码,但似乎没有发现任何东西,所以一些重点会有所帮助。我会尽我所能提供帮助。
【问题讨论】:
标签: c# entity-framework-4.1 poco nullreferenceexception