I am VERY new to ASP.NET MVC (3) and am having a hard time resolving a build error in Visual Studio:
The type or namespace name 'DbContext' could not be found (are you missing 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 errors I am getting are:
What am I missing?
I had the same issue. Turns out, you need the EntityFramework.dll reference (and not System.Data.Entity).
I just pulled it from the MvcMusicStore application which you can download from: http://mvcmusicstore.codeplex.com/
It's also a useful example of how to use entity framework code-first with MVC.