0

We have MVC project with EF approach. We got this error when we going to add migration

System.InvalidOperationException: Sequence contains more than one element at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source) at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<>c__DisplayClass76_1.<FindRenamedIndexes>b__5(String c) at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at System.Linq.Enumerable.SequenceEqual[TSource](IEnumerable1 first, IEnumerable1 second, IEqualityComparer1 comparer) at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<>c__DisplayClass76_0.<FindRenamedIndexes>b__3(<>f__AnonymousType402 <>h__TransparentIdentifier1) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(ModelMetadata source, ModelMetadata target, Lazy1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion) at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, Lazy1 modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator, String sourceModelVersion, String targetModelVersion) at System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace, Boolean ignoreChanges) at System.Data.Entity.Infrastructure.Design.Executor.ScaffoldInternal(String name, DbConnectionInfo connectionInfo, String migrationsConfigurationName, Boolean ignoreChanges) at System.Data.Entity.Infrastructure.Design.Executor.Scaffold.<>c__DisplayClass0_0.<.ctor>b__0() at System.Data.Entity.Infrastructure.Design.Executor.OperationBase.<>c__DisplayClass4_0`1.b__0() at System.Data.Entity.Infrastructure.Design.Executor.OperationBase.Execute(Action action) Sequence contains more than one element

** we change some key names for some models, I didn't know if it is relevant or not

and we didn't find any solutions work with EF approach, so what's the possible solutions for this error ?

MoSaleh
  • 23
  • 1
  • 7
  • Did you refresh the mapping between the database tables and the c# classes after making updates? Looks like he model was changed and doesn't match the database. – jdweng Oct 05 '20 at 14:11
  • Try to apply a migration with the new names for the keys (make sure EF knows they are the keys for that table). Should fix the problem. – Nolan Bradshaw Oct 05 '20 at 14:22
  • - @jdweng to be honest with you I'm a beginner and I don't know anything about mapping, I'll search about it – MoSaleh Oct 05 '20 at 17:01
  • - @NolanBradshaw I'm trying to add migration but it doesn't added because this error. – MoSaleh Oct 05 '20 at 17:04
  • Ah, my mistake misread the question. You may need to reset your migrations to a fresh state as they may have gotten out of sync. Can read more about it here: https://stackoverflow.com/questions/11679385/reset-entity-framework-migrations – Nolan Bradshaw Oct 05 '20 at 17:06

0 Answers0