Database Reference
In-Depth Information
Listing 2-16. Creating the Business POCO Entity Class
[Table("Business", Schema = "Chapter2")]
public class Business
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int BusinessId { get; protected set; }
public string Name { get; set; }
public string LicenseNumber { get; set; }
}
Create an eCommerce POCO entity class that inherits from the Business class using the
code in Listing 2-17.
3.
Listing 2-17. Creating the eCommerce POCO Entity Class
[Table("eCommerce", Schema = "Chapter2")]
public class eCommerce : Business
{
public string URL { get; set; }
}
Create a Retail POCO entity class that inherits from the Business class using the code
in Listing 2-18.
4.
Listing 2-18. Creating the Retail POCO Entity Class
[Table("Retail", Schema = "Chapter2")]
public class Retail : Business
{
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZIPCode { get; set; }
}
Add an auto-property of type DbSet<Business> to your DbContext subclass.
5.
How It Works
Both the Retail and the eCommerce tables are on the 0..1 side of a 1:0..1 relationship with the Business table.
This means that we could have a business with no additional information or a business with additional Retail or
eCommerce information. In object-oriented programming terms, we have a base type, Business, with two derived
types, Retail and eCommerce.
Because of the 1:0..1 relationship, we cannot have a row in the Retail or eCommerce tables without a
corresponding row in the Business table. In object-oriented terms, an instance of a derived type has the properties
of the base type. This concept of a derived type extending the properties of a base type is a key feature of inheritance.
In table per type (often abbreviated TPT) inheritance, each of the derived types is represented in separate tables.
 
Search WWH ::




Custom Search