Database Reference
In-Depth Information
Figure 5-12. A simple model that represents Club entity objects
Start by adding a console application project to Visual Studio entitled Recipe4 . Be certain to reference the Entity
Framework 6 libraries. Leveraging the NuGet Package Manager does this best. Right-click on Reference, and select
Manage NuGet Packages. From the Online tab, locate and install the Entity Framework 6 package. Doing so will
download, install, and configure the Entity Framework 6 libraries in your project.
To create the club entity, create a class entitled Club and copy the information into it from Listing 5-8.
Listing 5-8. Club Entity Class
public class Club
{
public int ClubId { get; set; }
public string Name { get; set; }
public string City { get; set; }
}
Next create a class entitled Recipe4Context , and add the code from Listing 5-9 to it, ensuring the class derives
from the Entity Framework DbContext class.
Listing 5-9. Context Class
public class Recipe4Context : DbContext
{
public Recipe4Context()
: base("Recipe4ConnectionString")
{
// disable Entity Framework Model Compatibility
Database.SetInitializer<Recipe4Context>(null);
}
public DbSet<Club> Clubs { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Club>().ToTable("Chapter5.Club");
}
}
 
Search WWH ::




Custom Search