As you are using Code First are you dropping and recreating the database on every load? If so are you seeding any data into the table in question?
Edit: Seeding data
Here's an example of a Database Initializer class that will seed data:
public class DatabaseInitializer : DropCreateDatabaseAlways<NameOfContext>
{
protected override void Seed(NameOfContext context)
{
SeedTestData(context);
base.Seed(context);
}
private static void SeedTestData(NameOfContext context)
{
var item = new Item
{
Id = 1
}
context.DatabaseObjectBeingAddedTo.Add(item);
}
}
Then in your global.asax file add the following to your Application_Start() method:
Database.SetInitializer(new DatabaseInitializer());
Second update, here is how you declare your context (linked to your database connection in your web.config via its name attribute) and the configuration for an entity (in this case RegionalSalesManager)
Context creation:
using Data.EntityConfigurations;
using Domain.Models;
using System.Data.Entity;
namespace Data.Contexts
{
public class ApplicationContext : DbContext
{
/// <summary>
/// Constructor
/// </summary>
public ApplicationContext()
: base("ConnectionStringName")
{ }
public DbSet<RegionalSalesManager> RegionalSalesManagers { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new RegionalSalesManagerConfiguration());
base.OnModelCreating(modelBuilder);
}
}
}
Entity Configuration:
using Domain.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
namespace Data.EntityConfigurations
{
public class RegionalSalesManagerConfiguration : EntityTypeConfiguration<RegionalSalesManager>
{
public RegionalSalesManagerConfiguration()
{
//Table
ToTable("RegionalSalesManagers");
//Primary key
HasKey(e => e.Id);
//Properties
Property(e => e.Id).HasColumnName("RegionalSalesManagerId").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
}
}
}