Database Reference
In-Depth Information
The downside of vertical splitting is that retrieving each instance of our entity now requires an additional join for
each additional table that makes up the entity type. This extra join is shown in Listing 2-10.
Listing 2-10.
Additional Join Required by Vertical Splitting
SELECT
[Extent1].[SKU] AS [SKU],
[Extent2].[Description] AS [Description],
[Extent2].[Price] AS [Price],
[Extent1].[ImageURL] AS [ImageURL]
FROM [dbo].[ProductWebInfo] AS [Extent1]
INNER JOIN [dbo].[Product] AS [Extent2] ON [Extent1].[SKU] = [Extent2].[SKU]
Nothing special is required to insert into or retrieve from the Product entity. Listing 2-11 demonstrates working
with the vertically split Product entity type.
Listing 2-11.
Inserting into and Retrieving from Our Model with the Product Entity Type
using (var context = new EF6RecipesContext())
{
var product = new Product { SKU = 147,
Description = "Expandable Hydration Pack",
Price = 19.97M, ImageURL = "/pack147.jpg" };
context.Products.Add(product);
product = new Product { SKU = 178,
Description = "Rugged Ranger Duffel Bag",
Price = 39.97M, ImageURL = "/pack178.jpg" };
context.Products.Add(product);
product = new Product { SKU = 186,
Description = "Range Field Pack",
Price = 98.97M, ImageURL = "/noimage.jp" };
context.Products.Add(product);
product = new Product { SKU = 202,
Description = "Small Deployment Back Pack",
Price = 29.97M, ImageURL = "/pack202.jpg" };
context.Products.Add(product);
context.SaveChanges();
}
using (var context = new EF6RecipesContext())
{
foreach (var p in context.Products)
{
Console.WriteLine("{0} {1} {2} {3}", p.SKU, p.Description,
p.Price.ToString("C"), p.ImageURL);
}
}