'DbContext' was not identified as a type or namespace.

asp.net-mvc asp.net-mvc-3 entity-framework visual-studio visual-studio-2010

Question

I am having trouble addressing a build problem in Visual Studio, despite the fact that I am VERY new to ASP.NET MVC (3):

'DbContext' as a type or namespace name could not be found (do you lack a using directive or an assembly reference?)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;

namespace MyProjectName.Models
{   
    public class MachineModel
    {
        // name
        [Required]
        [Display(Name = "Nom de la machine")]
        public string Name { get; set; }

        // IP
        [Required]
        [RegularExpression(@"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)",
           ErrorMessage = "Donnez une adresse IPv4 valide.")]
        [Display(Name = "Adresse IP de la machine")]
        public string IP { get; set; }
    }

    public class MachineDbContext : DbContext
    {
        public DbSet<MachineModel> Machines{ get; set; }
    }
}

The two mistakes I'm experiencing are:

  • 'DbContext' as a type or namespace name could not be found (do you lack a using directive or an assembly reference?)
  • Are you missing a using directive or an assembly reference? The type or namespace name "DbSet" could not be found.

What am I overlooking?

1
147
8/21/2013 7:38:08 AM

Accepted Answer

My situation was the same. It seems that the EntityFramework.dll reference is required (and not System.Data.Entity).

I just downloaded it via the MvcMusicStore program, which is available at http://mvcmusicstore.codeplex.com/.

It serves as a helpful illustration of how entity framework code-first may be used with MVC.

199
5/18/2011 5:24:21 PM

Popular Answer

You must make use of theSystem.Data.Entity Install the assy for your project orEntityFramework Everything will be configured for you by the NuGet package.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow