Database Reference
In-Depth Information
public partial class Violation
{
public int ViolationId { get; set; }
public string Description { get; set; }
public decimal Amount { get; set; }
public int TicketId { get; set; }
public virtual Ticket Ticket { get; set; }
}
public partial class EFRecipesEntities : DbContext
{
public EFRecipesEntities()
: base("name=EFRecipesEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Ticket> Tickets { get; set; }
public DbSet<Vehicle> Vehicles { get; set; }
public DbSet<Violation> Violations { get; set; }
The following is the output of the code in Listing 8-5:
Ticket: 1, Total Cost: $175.00
20 MPH over the speed limit
Broken tail light
Ticket: 2, Total Cost: $35.00
Parking in a no parking zone
How It Works
Lazy loading is the default setting when generating an Entity Data Model. The navigation entity properties are also
marked as virtual by default. You don't need to do anything explicitly to get this to work.
We have not done anything in the console program code to load the Violation object, which is related to the
Ticket object when the ticket context is fetched. Lazy loading enables the access of related entity properties at the
moment you access them in your code. It does not require you to query those properties at the time of the first loading
of the context object of the main entity, as we did using Include() method in the previous recipe.
8-4. POCO with Complex Type Properties
Problem
You want to use a complex type in your POCO entity.
Solution
Suppose that your model looks like the one in Figure 8-5 . In this model, the Name property is a complex type.
 
 
Search WWH ::




Custom Search