Busy learning MVC 3 and EF …
I have an existing database, I then create my Model aligned to my DB Table (Agency):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
namespace Dataset_Test.Models
{
public class Agency
{
public int AgencyID { get; set; }
[Required(ErrorMessage="Give me a name.")]
[StringLength(5)]
[MinLength(2)]
public string AgencyName { get; set; }
}
}
My DAL class:
public class DBContext: DbContext
{
public DbSet<Person> Persons { get; set; }
public DbSet<Agency> Agency { get; set; }
}
After using the controller generator popup to create the controller and views and then running the code:
private DBContext db = new DBContext();
//
// GET: /Agency/
public ViewResult Index()
{
return View(db.Agency.ToList());
}
I get an error which it simply cant find the Table as EF is automatically looking for the Table (dbo.Agencies) yet I have declared my Model Class as Agency, my question is how and where do you set the Table Name reference that the Model should be linked to, i.e. it should look for dbo.Agency and NOT dbo.Agencies?
Layout:

You need to add a
attribute to your Agency class