Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

PhoneBookDemo duplicate records created on Host startup #4949


User avatar
0
TimMackey created

In the section "Database Migrations", when creating file InitialPeopleCreator.cs the code is

namespace Acme.PhoneBookDemo.Migrations.Seed.Host
{
    public class InitialPeopleCreator
    {
        private readonly PhoneBookDemoDbContext _context;

        public InitialPeopleCreator(PhoneBookDemoDbContext context)
        {
            _context = context;
        }

        public void Create()
        {
            var douglas = _context.Persons.FirstOrDefault(p => p.EmailAddress == "[email protected]");
            if (douglas == null)
            {
                ...
            }
        }
    }
}

Later in the "Adding Database Migration" section the file 'InitialPeopleCreator.cs' is renamed 'InitialPeopleAndPhoneCreator.cs'. The code

var douglas = _context.Persons.FirstOrDefault(p => p.EmailAddress == "[email protected]");

introduces an error which is causing duplicate records for douglas.adams to be added to the database.

"[email protected]"

should be

"[email protected]")

1 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    thanks for the feedback. it's fixed by now.