Database Reference
In-Depth Information
Figure 3-18. A model with an Account entity type and its associated Order entity type
To start, this example leverages the Code-First approach for Entity Framework. In Listing 3-35, we create the
entity classes.
Listing 3-35. Account and Order Entity Types
public class Account
{
public Account()
{
Orders = new HashSet<Order>();
}
public int AccountId { get; set; }
public string City { get; set; }
public string State { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
public class Order
{
public int OrderId { get; set; }
public Decimal Amount { get; set; }
public int AccountId { get; set; }
public string ShipCity { get; set; }
public string ShipState { get; set; }
public virtual Account Account { get; set; }
}
Next, in Listing 3-36, we create the DbContext object, which is your gateway into Entity Framework functionality
when leveraging the Code-First approach.
Listing 3-36. The DbContext Object
public class EFRecipesEntities : DbContext
{
public EFRecipesEntities()
: base("ConnectionString") {}
Search WWH ::




Custom Search