我正在尝试将我的解决方案从 EF Code First 的 2011 年 6 月 CTP 升级到 EF 5 Beta。
我现在遇到以下问题:
创建上下文实例后,当我尝试查询上下文时,出现下面列出的异常。
似乎在 EF 的两个版本之间,有些东西发生了变化,现在在处理配置方面遇到了问题,但我不知道从哪里开始寻找。
提前非常感谢您的帮助。
保罗。
System.InvalidOperationException was unhandled by user code
HResult=-2146233079 Message=Sequence contains more than one element Source=System.Core StackTrace: at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source) at System.Data.Entity.ModelConfiguration.Configuration.Properties.Navigation.NavigationPropertyConfiguration.Configure(DbDatabaseMapping databaseMapping) at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.<>c__DisplayClass36.<ConfigureAssociationMappings>b__35(NavigationPropertyConfiguration c) at System.Data.Entity.ModelConfiguration.Utilities.IEnumerableExtensions.Each[T](IEnumerable
1 ts, Action1 action) at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigureAssociationMappings(DbDatabaseMapping databaseMapping) at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EdmEntityType entityType, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) 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.ForceOSpaceLoadingForKnownEntityTypes() at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext() at AccessAccounts.Accounts.DataAccess.Context.AccountsContext..ctor(String connectionString) in c:\Source\EnterpriseVS11\Enterprise\Data Access EF\Context\AccountsContext.cs:line 77 at AccessAccounts.BusinessService.Logon.LogonService.CheckDatabaseCompatibility() in c:\Source\EnterpriseVS11\Enterprise\Business Service\src\AccessAccounts\BusinessService\Logon\LogonService.cs:line 119 at AccessAccounts.BusinessService.Logon.LogonService.Logon(ApplicationTypes applicationType, String databaseName, String userName, String password, AuthenticationType authenticationMode) in c:\Source\EnterpriseVS11\Enterprise\Business Service\src\AccessAccounts\BusinessService\Logon\LogonService.cs:line 255 at SyncInvokeLogon(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) InnerException:
最佳答案
这是 EF5 Beta 1 中的一个已知错误。我们将在 Beta 2 中修复此问题,Beta 2 将在未来几周内删除。
该错误仅影响独立关联(CLR 类中不存在 FK 的关联),因此您可以通过切换到 FK 关联来解决此问题。
关于entity-framework - EF 5 Beta 1 Code First - 序列包含多个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9535622/