Database Reference
In-Depth Information
public partial class Employee
{
public Employee()
{
this.Name = new Name();
}
public int EmployeeId { get; set; }
public string Email { get; set; }
public Name Name { get; set; }
}
public partial class Name
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
public partial class EFRecipesEntities : DbContext
{
public EFRecipesEntities()
: base("name=EFRecipesEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Employee> Employees { get; set; }
}
The following is the output of the code in Listing 8-6:
Jordan, Bill email: BJordan@wildwestshow.com
Oakley, Annie email: aoakley@wildwestshow.com
How It Works
When you use complex types with POCO, keep in mind the following two rules:
class .
The complex type must be a
Inheritance cannot be used with complex type classes.
In Entity Framework, complex types do not leverage change tracking. Changes to complex types will not be
reflected in change tracking. This means that if you mark the properties on a complex type as virtual , there is no
change-tracking proxy support. All change tracking is snapshot-based.
When you delete or update a POCO entity with a complex type without first loading it from the database, you need
to be careful to create an instance of the complex type. In Entity Framework, instances of complex types are structurally
part of the entity, and null values are not supported. The code in Listing 8-7 illustrates one way to handle deletes.
 
Search WWH ::




Custom Search