Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# Entity Framework Migrations Getting Started with Using Migrations Using a Preprocessor Directive to Exclude Test Data

Cant tell what I'm doing wrong

I've rewatched videos and i can't figure out what I'm missing in my code.

Configuration.cs
using System.Data.Entity.Migrations;

namespace Treehouse.CodeChallenges
{
    public class Configuration : DbMigrationsConfiguration<Context>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }
#if DEBUG
        protected override void Seed(Context context)
        {
            context.Students.AddOrUpdate(
                s => s.Id,
                new Student() { Id = 1, FirstName = "John", LastName = "Smith" },
                new Student() { Id = 2, FirstName = "Sally", LastName = "Jones" }
            );
            #endif
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,210 Points

You've got the right idea, but the preprocessor directives are placed here at different nesting levels. They should both be inside the "Seed" method definition, to control the compilation of the call to "AddOrUpdate".