none
Can't compile the code first tutorial RRS feed

  • Question

  • Hi, i'm trying to follow the following webcast:

    http://channel9.msdn.com/Events/TechEd/Europe/2010/DEV212

    what they do is something like that, it's mvc:

    they created a model:

    namespace MVCCodeFirst.Models
    {
        public class User
        {
            public User()
            {
                Chirps = new List<Chirp>();
            }
    
            public int Id { get; set; }
    
            public string Name { get; set; }
    
            public ICollection Chirps { get; set; }
        }
    
        public class Chirp
        {
            public int Id { get; set; }
    
            public User User { get; set; }
        }
    
        public class ChirpContext : DbContext
        {
            public DbSet<User> Users { get; set; }
    
            public DbSet<Chirp> Chirps { get; set; }
    
    
        }
    }


    and a controller:

    using System.Web.Mvc;
    using MVCCodeFirst.Models;
    
    namespace MVCCodeFirst.Controllers
    {
        public class UserController : Controller
        {
            ChirpContext db = new ChirpContext();
            //
            // GET: /User/
    
            public ActionResult Index()
            {
                return View(db.Users.ToList());
            }
    
    .......

    the problem is in this line :

    db.Users.ToList());

    , i can't seem to be able to use ToList() with a DbSet.

    just to mention i'm using

    Entity Framework 4.1 and not efctp5 as they use because it said when i tried to download it that this is the latest one, is that why i have a problem?

     

     

    Monday, January 30, 2012 6:54 PM

Answers

  • Hi ronenfe;

    The ToList method is found in System.Linq namespace so try adding the following using statement :

    using System.Linq;

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by ronenfe Tuesday, January 31, 2012 8:50 AM
    Monday, January 30, 2012 8:12 PM

All replies

  • Hi ronenfe;

    The ToList method is found in System.Linq namespace so try adding the following using statement :

    using System.Linq;

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by ronenfe Tuesday, January 31, 2012 8:50 AM
    Monday, January 30, 2012 8:12 PM
  • Thanks, that worked, strange,  usually the vs can resolve those issues.
    Tuesday, January 31, 2012 8:50 AM
  •  

    Not a problem, glad to help.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Tuesday, January 31, 2012 2:00 PM