Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

HELP with framework question??

In Configuration.cs update the Seed method so that the database is only seeded with the students test data when the application is being built with the Debug build configuration. To do that, wrap the call to the context's Students DbSet property's AddOrUpdate method in an #if preprocessor directive and test for the presence of the DEBUG symbol.

I keep getting bummer and i;m not for sure whats wrong.

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
        }
    }
}

2 Answers

Steven Parker
Steven Parker
221,451 Points

Always make sure parentheses and braces match inside a conditional.

Otherwise, when the condition is not met, the code will not compile.

Also, you don't want to make the method itself conditional, just the code in the body.

so i just noticed it wants me to change " protected override void Seed(Context context)" but i'm not sure what to change it to. i re watch the video and still don't get it.

Steven Parker
Steven Parker
221,451 Points

I'm not sure what you mean. But if you just move that "#if DEBUG" to the correct line it will pass the challenge.

you also capitalized the 'if' in #endIf. try #endif