You're connecting to the Database fine. The actual DB model and the codefirst model are not in sync, hence the error.
You're adding a DbSet to the DBContext for video, but no such table exists within your current database. Unless your database initializer states to create the models when it does not exist, this is exactly the error I'd expect you to get.
Also, I see no mapping class defined or mentioned that maps the model class back to the database table.
Take a look at http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application. This gets into database intializers towards the end. The other option is to simply create the table manually.
So, problem one, no database initializer (or pre-defined table). Problem two, no mapping class for the table and OnModelCreating, at least from what you've shown. It's entirely possible that you're not using the fluent api to define your mappings and instead are just using attributes in the video model, but again, you didn't show that, so I'm going to show you the fluent way.
EDIT:
I've updated this code from a test project I created locally with your naming conventions. This 100% works. These are the exact class I created or reverse engineered.
public class videoDBContext : DbContext
{
static videoDBContext()
{
Database.SetInitializer<videoDBContext>(null);
}
public videoDBContext()
: base("Name=videoDBContext")
{
}
public DbSet<Video> Videos { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new VideoMap());
}
}
domain class
public class Video
{
public int Id { get; set; }
public string Description { get; set; }
}
and the mapping class
public class VideoMap : EntityTypeConfiguration<Video>
{
public VideoMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Description)
.IsRequired()
.HasMaxLength(50);
// Table & Column Mappings
this.ToTable("Video");
this.Property(t => t.Id).HasColumnName("Id");
this.Property(t => t.Description).HasColumnName("Description");
}
}
and then my controller action
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
using (videoDBContext context = new videoDBContext())
{
var list = context.Videos.ToList();
}
return View();
}
This returns whatever "videos" I added to the table.
As for what goes where, it doesn't really matter if you're doing everything in one project. Pick a spot. Here's how things shook out in mine.
You have to remember there's additional upfront effort when working with code first to get things up and running. Once you get the hang of it however, it's a really nice way of working with databases.