Database Reference
In-Depth Information
public class Event
{
public int EventId { get; set; }
public string EventName { get; set; }
public DateTime EventDate { get; set; }
public int ClubId { get; set; }
public virtual Club Club { get; set; }
}
Next create a class entitled Recipe7Context , and add the code from Listing 5-15 to it, ensuring the class derives
from the Entity Framework DbContext class.
Listing 5-15. Context Class
public class Recipe7Context : DbContext
{
public Recipe7Context()
: base("Recipe7ConnectionString")
{
// Disable Entity Framework Model Compatibility
Database.SetInitializer<Recipe7Context>(null);
}
public DbSet<Club> Clubs { get; set; }
public DbSet<Event> Events { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Club>().ToTable("Chapter5.Club");
modelBuilder.Entity<Event>().ToTable("Chapter5.Event");
}
}
Next add an App.Config class to the project, and add the code from Listing 5-16 to it under the
ConnectionStrings section.
Listing 5-16. Connection String
<connectionStrings>
<add name="Recipe7ConnectionString"
connectionString="Data Source=.;
Initial Catalog=EFRecipes;
Integrated Security=True;
MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
To use the Include() method in combination with a group by clause, the Include() method must be placed
after filtering and grouping operations for the parent entity. The code in Listing 5-17 demonstrates this approach.
 
Search WWH ::




Custom Search