Part 12 Table splitting in entity framework04:33

  • 0
Published on December 12, 2017

Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

In this video we will discuss Table splitting in entity framework with database first approach. Table Splitting is the opposite of Entity Splitting.

We discussed Entity Splitting in Part 10 and 11 of Entity Framework tutorial.

Entity Splitting refers to mapping an entity to two or more tables when the tables share a common key.

Mapping multiple entities to a single table is called table splitting.

One common entity framework interview question is, What is the main reason for using Table Splitting?
Table Splitting is useful when you want to delay the loading of some properties with large data when using lazy loading. For example, if you have Employee entity and if it contains Photo property that would return large binary data, and if we use this Photo property only on a few pages in our application, then it does not make sense from a performance perspective to load this property every time we load the Employee entity. Using lazy loading load it only on the pages where we need to display Employee photo.

When we use ADO.NET Entity Framework to generate entities from the database using database first approach, by default one entity will be created, i.e Empoyee entity.

Let’s say, we will not be using Email, Mobile and Landline properties as often as we would be using FirstName, LastName, and Gender properties. If all of these properties are present in one Employee entity, then everytime we load this entity, all the properties will be automatically loaded. So let’s create 2 entities (Employee & EmployeeContactDetail). This enables us to load EmployeeContactDetails only when needed.

To achieve this:
1. Right click on the entity designer and select “Add Entity” option from the context menu. Set
a) Entity Name = EmployeeContactDetail
b) Bae type = (None)
c) Entity Set = EmployeeContactDetails
d) Create Key Property = Checked
e) Property Name = EmployeeID

2. Cut Email, Mobile and LandLine properties from Employee entity and paste them in EmployeeContactDetail entity

3. Right click on the entity designer and select “Add – Association” option from the context menu.

4. Right click on the association and select “Properties”. In the Properties window, click on the ellipsis button next to “Referential Constraint” property and fill in the required details.

5. Right click on “EmployeeContactDetail” entity and select “Table Mapping” option from the context menu. Select “Employees” table and map EmployeeId, Email, Mobile and Landline properties of the entity to the respective columns of the table.

https://cafeadobro.ro/

https://www.stagebox.uk/wp-includes/depo10-bonus10/

https://iavec.com.br/

Enjoyed this video?
"No Thanks. Please Close This Box!"