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 trialLarry Singleton
18,946 PointsList Queries
Link: https://teamtreehouse.com/library/entity-framework-basics/linq-queries/writing-a-list-query
Question: In Repository.cs update the GetCourses method to return a list of the available courses.
Instantiate an instance of the Context class within a using statement
Return the results of calling ToList on the context's Courses DbSet property
ERRORS
Repository.cs(14,37): error CS1525: Unexpected symbol `:', expecting `)' or `,'
Repository.cs(14,42): error CS1002: ; expected
Repository.cs(14,42): error CS1525: Unexpected symbol `,', expecting `)' or `,'
Repository.cs(14,57): error CS1525: Unexpected symbol `)', expecting `;' or `}'
Repository.cs(18,0): error CS1525: Unexpected symbol `}'
Compilation failed: 5 error(s), 0 warnings
Provided Code
Repository.cs
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
namespace Treehouse.CodeChallenges
{
public static class Repository
{
public static List<Course> GetCourses()
{
return null; // TODO
}
}
}
My last attempt:
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
namespace Treehouse.CodeChallenges
{
public static class Repository
{
public static List<Course> GetCourses()
{
using (var context = new Context())
{
var courses = context.Courses.ToList();
Console.WriteLine(# of Courses: {0} Courses.Count);
}
}
}
}
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
namespace Treehouse.CodeChallenges
{
public static class Repository
{
public static List<Course> GetCourses()
{
return null; // TODO
}
}
}
3 Answers
Steven Parker
231,248 PointsYour "last attempt" was nearly there.
Your using statement was correct, and you got the list you needed into your courses variable. If you had passed that back in a return you would have completed the challenge.
But instead, you have a call to WriteLine with some arguments that are definitely not C# syntax!
Larry Singleton
18,946 PointsI do try to look up how to resolve these challenges on other sites when I can't figure out the challenge. Being that I'm really not sure what is or what isn't C# syntax at my level, pointing it out with out illustrating what you're talking about, simply goes right over my head.
I do appreciate your help, it's still all Greek to me.
Tanmoy Chowdhury
12,622 Pointsusing System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
namespace Treehouse.CodeChallenges
{
public static class Repository
{
public static List<Course> GetCourses()
{
using (var context = new Context())
{
return context.Courses.ToList();
}
}
}
}