Database Reference
In-Depth Information
Figure 3-16. A model with an Event entity type that has properties for the event's name, state, and city
To start, this example leverages the Code-First approach for Entity Framework. In Listing 3-31, we create the
entity classes.
Listing 3-31. Event Entity Type
public class Event
{
public int EventId { get; set; }
public string Name { get; set; }
public string State { get; set; }
public string City { get; set; }
}
Next, in Listing 3-32, we create the DbContext object, which is your gateway into Entity Framework functionality
when leveraging the Code-First approach.
Listing 3-32. The DbContext Object
public class EFRecipesEntities : DbContext
{
public EFRecipesEntities()
: base("ConnectionString") {}
public DbSet<Event> Events { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Event>().ToTable("Chapter3.Event");
base.OnModelCreating(modelBuilder);
}
}
Search WWH ::




Custom Search