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 LINQ Queries Writing a List Query

How do you instantiate instance of the Context class? How do you return results of calling ToList on context's DbSet?

I can't see many similarities between the video and the challenge. I'm not able to draw equivalencies (e.g. his "ComicBook" = my GetCourses? .....Context?... Repository.cs? Also I'm not sure if the first part of the video was relevant to the challenge; he uses "context.Database.Log = (message) => Debug.Writeline (message);" Do I need that?

Repository.cs
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

namespace Treehouse.CodeChallenges
{

    context.Database.Log = (message) => Debug.Writeline (message);


    public static class Repository
    {
        public static List<Course> GetCourses()
        {
            return null; 

            var GetCourses = GetCoursesQuery.ToList();
            Console.WriteLine = ("# of GetCourses: {0}, GetCourses.Count");
        }
    }
}

1 Answer

Steven Parker
Steven Parker
229,608 Points

The use of "context" in the video is very similar to what you will do in the challenge. You'll create it "within a using statement" as mentioned in the instructions. And the "ComicBooks" in the video is a DbSet, similar to the "Courses" in the challenge.

A few additional hints:

  • you can remove the "return null;" line, you will be returning a course list
  • there is nothing defined named "GetCoursesQuery"
  • you don't need to write anything to the console for this challenge