Database Reference
In-Depth Information
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public int DepartmentId { get; set; }
public virtual Department Department { get; set; }
}
Next create a class entitled Recipe8Context , and add the code from Listing 5-19 to it, ensuring that the class
derives from the Entity Framework DbContext class.
Listing 5-19. Context Class
public class Recipe8Context : DbContext
{
public Recipe8Context()
: base("Recipe8ConnectionString")
{
// Disable Entity Framework Model Compatibility
Database.SetInitializer<Recipe8Context>(null);
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Company>().ToTable("Chapter5.Company");
modelBuilder.Entity<Employee>().ToTable("Chapter5.Employee");
modelBuilder.Entity<Department>().ToTable("Chapter5.Department");
}
public DbSet<Company> Companies { get; set; }
public DbSet<Department> Departments { get; set; }
public DbSet<Employee> Employees { get; set; }
}
Next add an App.Config class to the project, and add the code from Listing 5-20 to it under the
ConnectionStrings section.
Listing 5-20. Connection String
<connectionStrings>
<add name="Recipe8ConnectionString"
connectionString="Data Source=.;
Initial Catalog=EFRecipes;
Integrated Security=True;
MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
 
Search WWH ::




Custom Search