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

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
231,271 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
231,271 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