entity-framework - EF 5 Beta 1 Code First - 序列包含多个元素

标签 entity-framework ef-code-first

我正在尝试将我的解决方案从 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](IEnumerable1 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.RetryLazy2.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/

相关文章:

mysql - 无法使用 MySql 运行代码优先迁移 - RenameColumn

c# - EF5 ObjectContext : How to replace IQueryable<T>. 包含(路径)与 context.T.Attach()

c# - .NET Entity Framework : Add-Migration is too slow

c# - 使用 Entity Framework 代码保存分离的对象图首先导致主键冲突

ef-code-first - Entity Framework : I set the foreign key, SaveChanges 然后访问导航属性,但它不会加载相关实体。为什么不?

c# - 一对多关系在 EF 中不起作用

asp.net-mvc - EF CF 和现有一对一关系的问题

c# - 为什么 EF 中 context.SaveChanges 的更改不会影响我的 mdf 文件?

entity-framework - 配置 npgsql 以与 .NET 3.5 和 EF 一起使用

c# - 使用 Entity Framework 选择单行。 Entity Framework 没有生成sql语句吧?