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 Basics Extending Our Entity Data Model Defining and Using a One-to-Many Relationship

fed up with these challenges

using System.Collections.Generic;

namespace Treehouse.CodeChallenges { public class Teacher { public Teacher() //3rd objective??? { Courses = new List<Course>(); } public ICollection<Course> Courses { get; set; } // 2nd objective }
}

What can be wrong??????????? Really...

Course.cs
using System.Collections.Generic;

namespace Treehouse.CodeChallenges
{
public class Teacher
{
    public Teacher() //3rd objective???
        {
            Courses = new List<Course>();
        }
    public ICollection<Course> Courses { get; set; } // 2nd objective
    }  
}
Teacher.cs
namespace Treehouse.CodeChallenges
{
    public class Teacher
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
}

2 Answers

Hi there,

I think the issue here is where the code was added for the second set of objectives - it should be under Teacher.cs. It looks like you've deleted the contents of Course.cs and placed a Teacher class there instead. Generally the challenges will build on what you've already done - you usually don't want to delete something you did for a previous step unless it specifically tells you to. It can be sneaky, but keep an eye out for when an objective specifies a file - sometimes there are multiple tabs and you need to switch.

You've got the right idea with the code, though - it just needs to be in the right file, with the initial code and the previous step intact. Should look something like:

Course.cs (first step)

namespace Treehouse.CodeChallenges
{
    public class Course
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public int Length { get; set; }
        public int TeacherId { get; set; }
        public Teacher Teacher {get; set; }
    }
}

Teacher.cs (second step)

using System.Collections.Generic;

namespace Treehouse.CodeChallenges
{
    public class Teacher
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public ICollection<Course> Courses {get; set; }

        public Teacher() {
            Courses = new List<Course>();
        }
    }
}

Hope this helps!

Thank you very much for your response. You are right, I noticed that after I posted this.Thank you!