Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
The name _reviews don't exist in this context
Message
De
01/12/2011 15:12:47
John Baird
Coatesville, Pennsylvanie, États-Unis
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Problèmes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01530088
Message ID:
01530099
Vues:
48
This message has been marked as the solution to the initial question of the thread.
>>>Hi everybody,
>>>
>>>I've been trying to follow along the PluralSight training in ASP.NET.MVC. So, two first courses I watched and immediatelly copied everything along with Scott.
>>>
>>>Now, in doing the 3rd part 'Razor views' he skipped some unrelated steps of prototyping a database. Since I want to continue following along the course and not just watch, I thought I will try to replicate the missed step on my own.
>>>
>>>So, I capture this screen (see attached) and after creating the Restaurant class with just Name property and adding properties to match in the RestaurantReview class I'm having now this in the FoodDb class:
>>>
>>>
>>>using System;
>>>using System.Collections.Generic;
>>>using System.Linq;
>>>using System.Web;
>>>
>>>namespace OdeToFood.Models
>>>{
>>>    public class FoodDb
>>>    {
>>>        static FoodDb()
>>>        {
>>>            _reviews = new List<RestaurantReview>();
>>>            _reviews.Add(new RestaurantReview
>>>            {
>>>                Body = "A fantastic culinary pleasure.",
>>>                Created = DateTime.Now,
>>>                ID = 1,
>>>                Rating = 9,
>>>                Restaurant = new Restaurant
>>>                {
>>>                    Name = "Mannequin Pis"
>>>                }
>>>            });
>>>        }
>>>    }
>>>}
>>>
>>>E.g. exactly as shown in the slide. However, in my case _reviews are underlined with blue and I get the error message
>>>
>>>Error 5 The name '_reviews' does not exist in the current context c:\dev\OdeToFood\OdeToFood\OdeToFood\Models\FoodDB.cs 12 13 OdeToFood
>>>
>>>So, what exactly am I missing in my attempts to reproduce the model prototype?
>>
>>
>>Aren't you missing the type in declaration?
>>
>>List<RestaurantReview> _reviews = new List<RestaurantReview>();
>>
>
>I was thinking I need something like this, but why Scott's code in the slide doesn't show it? I would assume he is using the correct code?
>
>Anyway, I'll try adding it for now and hopefully can move a bit along.


The _reviews means that the variable is a class level field variable. It should be defined between the Class declaration and the constructor as:
List<RestaurantReview> _reviews;
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform