C# EF序列包含多个元素

C# EF序列包含多个元素,c#,asp.net-mvc,entity-framework,C#,Asp.net Mvc,Entity Framework,我们有采用EF方法的MVC项目。 我们在添加迁移时遇到此错误 System.InvalidOperationException:序列包含多个元素 在System.Data.Entity.Migrations.Infrastructure.EdmModelDifference.c_uu在System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source)中显示System.Linq.Enumerable中的Class76_1.b_

我们有采用EF方法的MVC项目。 我们在添加迁移时遇到此错误

System.InvalidOperationException:序列包含多个元素 在System.Data.Entity.Migrations.Infrastructure.EdmModelDifference.c_uu在System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable
1 source)中显示System.Linq.Enumerable中的Class76_1.b_u5(字符串c)。其中SelectListIterator
2.MoveNext() 在System.Data.Entity.Migrations.Infrastructure.EdmModelDifference.c_uDisplayClass76_0.b_u3(f_u匿名类型402 h_u透明标识符1) 在System.Linq.Enumerable.whereselectEnumerableInterator
2.MoveNext()在System.Collections.Generic.List
1..ctor(IEnumerable
1 collection)在System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source) 位于System.Data.Entity.Migrations.Infrastructure.EdmModelDifference.Diff(ModelMetadata源、ModelMetadata目标、Lazy
1 modificationCommandTreeGenerator、MigrationSqlGenerator MigrationSqlGenerator、String sourceModelVersion、String targetModelVersion)的System.Data.Entity.Migrations.Infrastructure.EdmModelDifference.Difference(XDocument sourceModel、XDocument targetModel、Lazy
1 modificationCommandTreeGenerator、MigrationSqlGenerator MigrationSqlGenerator、String sourceModelVersion、String targetModelVersion) 位于System.Data.Entity.Migrations.DbMigrator.Scaffold(字符串migrationName、字符串命名空间、布尔值ignoreChanges) 位于System.Data.Entity.Infrastructure.Design.Executor.ScaffolInternal(字符串名称、DbConnectionInfo连接信息、字符串迁移配置名称、布尔值ignoreChanges) 在System.Data.Entity.Infrastructure.Design.Executor.Scaffold.c__DisplayClass0_0.b_0()中 在System.Data.Entity.Infrastructure.Design.Executor.OperationBase.c__DisplayClass4_0`1.b__0()中 位于System.Data.Entity.Infrastructure.Design.Executor.OperationBase.Execute(操作) 序列包含多个元素

**我们更改了一些型号的关键名称,我不知道是否相关

我们没有发现任何解决方案与EF方法有效,
那么,此错误的可能解决方案是什么?

在进行更新后,是否刷新了数据库表和c#类之间的映射?看起来模型已更改,并且与数据库不匹配。尝试使用键的新名称应用迁移(确保EF知道它们是该表的键)。应该可以解决问题。-@jdweng说实话,我是一个初学者,对映射一无所知,我会搜索它。-@NolanBradshaw我正在尝试添加迁移,但没有添加,因为这个错误。啊,我的错误误读了问题。你可能需要将迁移重置为新状态,因为它们可能已经不同步。Can请在此处阅读更多信息: