I’ve just switched our project to try Entity Framework 5.0 RC, running under .NET 4.0. Aside from updating namespace references, we haven’t made any code changes. I’m getting the following the first time we try to access an entity framework object:
at System.Data.Entity.ModelConfiguration.Conventions.ForeignKeyNavigationPropertyAttributeConvention.System.Data.Entity.ModelConfiguration.Conventions.IEdmConvention<System.Data.Entity.Edm.EdmNavigationProperty>.Apply(EdmNavigationProperty navigationProperty, EdmModel model)
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.EdmConventionDispatcher.Dispatch[TEdmDataModelItem](TEdmDataModelItem item)
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.EdmConventionDispatcher.VisitEdmNavigationProperty(EdmNavigationProperty item)
at System.Data.Entity.Edm.Internal.DataModelItemVisitor.VisitCollection[T](IEnumerable`1 collection, Action`1 visitMethod)
at System.Data.Entity.Edm.Internal.EdmModelVisitor.VisitDeclaredNavigationProperties(EdmEntityType entityType, IEnumerable`1 navigationProperties)
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.EdmConventionDispatcher.VisitEdmEntityType(EdmEntityType item)
at System.Data.Entity.Edm.Internal.DataModelItemVisitor.VisitCollection[T](IEnumerable`1 collection, Action`1 visitMethod)
at System.Data.Entity.Edm.Internal.EdmModelVisitor.VisitEntityTypes(EdmNamespace edmNamespace, IEnumerable`1 entityTypes)
at System.Data.Entity.Edm.Internal.EdmModelVisitor.VisitEdmNamespace(EdmNamespace item)
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.EdmConventionDispatcher.VisitEdmNamespace(EdmNamespace item)
at System.Data.Entity.Edm.Internal.DataModelItemVisitor.VisitCollection[T](IEnumerable`1 collection, Action`1 visitMethod)
at System.Data.Entity.Edm.Internal.EdmModelVisitor.VisitNamespaces(EdmModel model, IEnumerable`1 namespaces)
at System.Data.Entity.Edm.Internal.EdmModelVisitor.VisitEdmModel(EdmModel item)
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.EdmConventionDispatcher.VisitEdmModel(EdmModel item)
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.EdmConventionDispatcher.Dispatch()
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ApplyModel(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.Initialize()
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.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
at BackEnd.Facade.Implementations.UserService.GetUserByUserName(String userName) in c:\Development\FundApps\Rapptr\src\FundApps.Rapptr.ServiceLayer\Facade\Implementations\UserService.cs:line 61
at FundApps.Rapptr.Common.Web.Security.WebUserContextModule.OnPostAuthenticateRequest(HttpContextBase context) in c:\Development\FundApps\Rapptr\src\FundApps.Rapptr.Common.Web\Security\WebUserContextModule.cs:line 54
at FundApps.Common.Mvc.BaseHttpModule.<Init>b__1(Object sender, EventArgs e) in c:\Development\FundApps\Rapptr\src\FundApps.Common.Mvc\BaseHttpModule.cs:line 14
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Does anyone have any suggestions as to what might cause this and how to narrow it down?
UPDATE: This bug was fixed in EF5 RTM.
This is a bug in EF5. It happens when you have a 1:1 relationship and also use the
ForeignKeyattribute to explicitly specify the FK. For example:In OnModelCreating:
The workaround is to remove the
ForeignKeyattribute. It is not needed in this case because the 1:1 relationship must be PK to PK since that is all that EF supports in this case.