0

I have just added these lines in my Project > DataLayer > Property.cs

public Property()
{
    this.Amenties = new List<Amenity>();
}

public string Latitude { get; set; }
public string Longitude { get; set; }
public virtual ICollection<Amenity> Amenties  { get; set; }

and in my Project > DataLayer > Amenties.cs

public virtual ICollection<Property> Properties { get; set; }

Getting the following output on running update-database

    PM> update-database
    Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
    Applying explicit migrations: [201509141729336_PropLatLongAmt].
    Applying explicit migration: 201509141729336_PropLatLongAmt.
    Running Seed method.
    System.InvalidOperationException: Sequence contains more than one element
       at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
       at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2[TResult](IEnumerable`1 sequence)
       at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
       at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
       at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
       at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
       at System.Data.Entity.Migrations.DbSetMigrationsExtensions.AddOrUpdate[TEntity](DbSet`1 set, IEnumerable`1 identifyingProperties, InternalSet`1 internalSet, TEntity[] entities)
       at System.Data.Entity.Migrations.DbSetMigrationsExtensions.AddOrUpdate[TEntity](IDbSet`1 set, Expression`1 identifierExpression, TEntity[] entities)
       at SitefinityWebApp.Migrations.Configuration.Seed(TopSpotDbContext context) in e:\My Work\salman\Topspot\SitefinityWebApp\Web\Migrations\Configuration.cs:line 40
       at System.Data.Entity.Migrations.DbMigrationsConfiguration`1.OnSeed(DbContext context)
       at System.Data.Entity.Migrations.DbMigrator.SeedDatabase()
       at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.SeedDatabase()
       at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
       at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
       at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
       at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
       at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
       at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
       at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
       at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
    Sequence contains more than one element

There are no duplication of fields have checked it, only one Latitude and one Longitude and Amenties that I have added in the entire (POCO) property class. I run add-migration before running update-database once

2 Answers2

0

Try renaming the Property class and Properties property to something else. Could be that these are reserved words that leads to this problem.

Veselin Vasilev
  • 3,698
  • 1
  • 15
  • 21
  • The property class was there previously and the code was working fine. Also the class property, "Properties" I tried renaming to "property" but am going no where with the error. – hasnainwasaya Sep 15 '15 at 04:49
0

Found the problem by debugging the update-database

Debug code-first Entity Framework migration codes

I did try to revert the changes i had done back and was still getting the same error so I followed the instructions in above link and found that error was at line 40 as indicated in the stack output

   at SitefinityWebApp.Migrations.Configuration.Seed(TopSpotDbContext context) in PROJECT_DIRECTORY\SitefinityWebApp\Web\Migrations\Configuration.cs:line 40
Community
  • 1
  • 1