John,
The SQL CE database is automatically created by Entity Framework. That capability is there if you use Code-First. The DbContext class is responsible for further customizing the creation of the database. Following is the DbContext from TempHire. TempHireDbInitializer is responsible for when and how you want EF to create the database. In this case the database is created every time the model changes or the database doesn't exist and then the Seed method is called to fill it with initial data.
[DataSourceKeyName("TempHireEntities")]
internal class TempHireDbContext : DbContext
{
static TempHireDbContext()
{
// This is currently a DevForce requirement in order to use SLQ CE with Code-First.
// See http://drc.ideablade.com/xwiki/bin/view/Documentation/code-first-sqlce
// Remove if not using SQL CE.
Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
}
public TempHireDbContext(string connection = null)
: base(connection)
{
Database.SetInitializer(new TempHireDbInitializer());
// DevForce already performs validation
Configuration.ValidateOnSaveEnabled = false;
}
public DbSet<StaffingResource> StaffingResources { get; set; }
public DbSet<Address> Addresses { get; set; }
public DbSet<AddressType> AddressTypes { get; set; }
public DbSet<PhoneNumber> PhoneNumbers { get; set; }
public DbSet<PhoneNumberType> PhoneNumberTypes { get; set; }
public DbSet<Rate> Rates { get; set; }
public DbSet<RateType> RateTypes { get; set; }
public DbSet<State> States { get; set; }
public DbSet<WorkExperienceItem> WorkExperienceItems { get; set; }
public DbSet<Skill> Skills { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Ignore<EntityAspect>();
}
}