I'm a student taking the ASP.NET core fundamentals on pluralsight by Scott Allen. I'm having issues with a LINQ statement where r is not defined. The whole file is below but I am really only having issues with the last part and defining r. r is not defined in this file or any of the other files I have worked with in the course thus far. In the video Scott just seems to type r no problem and it recognizes r as a restaurant. When i do the same r is not recognized as anything, I feel like I am missing something pretty basic here as to why r is not being recognized or I need to define it somewhere else.
public interface IRestaurantData
{
IEnumerable<Restaurant> GetAll();
}
public class InMemoryRestaurantData : IRestaurantData
{
readonly List<Restaurant> restaurants;
public InMemoryRestaurantData()
{
restaurants = new List<Restaurant>()
{
new Restaurant { Id = 1, Name = "Scott's Pizza", Location = "Maryland", Cuisine = CuisineType.Italian},
new Restaurant { Id = 2, Name = "Cinnamon Club", Location = "London", Cuisine = CuisineType.Indian},
new Restaurant { Id = 3, Name = "La Costa", Location = "California", Cuisine = CuisineType.Mexican}
};
}
public IEnumerable<Restaurant> GetAll()
{
return from r in restaurants
orderby r.Name
select r;
}
}
namespace OdeToFood.Core
{
public class Restaurant
{
public int Id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
public CuisineType Cuisine { get; set; }
}
}
Seems like the using statement using System.Linq
is missing. Try adding it and it should work.
Add using System.Linq
to your namespaces. If you are using VS, just press CTRL
+.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With