Skip to content

This repository addresses the challenges of multiple users management and introduces two popular inheritance modelling strategies: TPH (Table Per Hierarchy) and TPT (Table Per Type). The application integrates with IdentityFramework to provide robust user authentication and authorization capabilities .

3umarG/Inheritance-Mapping-Identity-Framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mapping Strategy for Inheritance Relationship in .NET API 6 Application

Overview

This repository contains a .NET API 6 application that demonstrates two different mapping strategies for handling inheritance relationships: TPH (Table Per Hierarchy) and TPT (Table Per Type) with IdentityFramework for User Management . The aim of this project is to compare these two strategies in terms of storage efficiency, performance, and maintainability.

Table of Contents

Introduction

In object-oriented programming, inheritance allows a class (subclass) to inherit properties and behaviors from another class (base class). When working with a database, mapping these inheritance relationships efficiently becomes important. This project explores two common mapping strategies: TPH (Table Per Hierarchy) and TPT (Table Per Type) in a .NET API 6 application.

TPH strategy involves storing all subclasses of a hierarchy in a single table, utilizing a discriminator column to differentiate between different types. On the other hand, TPT strategy uses a separate table for each subclass, linked to the base class table through foreign keys.

By comparing these strategies, we aim to understand the trade-offs between storage efficiency, performance, and ease of maintenance, helping developers make informed decisions when designing their data models.

Installation

To run the project locally, follow these steps:

  1. Clone the repository to your local machine.
  2. Ensure you have .NET SDK 6 installed.
  3. Restore the NuGet packages by running dotnet restore in the project's root directory.
  4. Build the application using dotnet build.
  5. Run the application with dotnet run.

Mapping Strategies

TPH (Table Per Hierarchy) Strategy

In TPH strategy, all subclasses of a hierarchy are stored in a single table. A discriminator column is used to differentiate between different entity types in the table. This approach simplifies the database schema but can lead to redundancy and less efficient storage, as all properties for all subclasses are stored in one table.

TPT (Table Per Type) Strategy

In TPT strategy, each subclass has its own separate table, which is linked to the base class table through foreign keys. This approach allows for a more normalized database schema but can result in complex queries when fetching data involving multiple subclasses.

Comparison

Let's compare the TPH and TPT strategies based on three key criteria:

Storage Efficiency

  • TPH : This strategy can lead to redundant storage, as all properties for all subclasses are stored in a single table. However, it may require fewer joins for certain queries.
  • TPT : This strategy results in a more normalized schema, potentially reducing redundancy. Each subclass has its own table, leading to more efficient storage of properties unique to each subclass. However, queries may require more joins due to the separate tables.

Performance

  • TPH : With fewer joins required, certain queries may have better performance compared to TPT. However, queries involving complex inheritance hierarchies may perform slower due to the need for filtering based on the discriminator column.
  • TPT : The normalized schema may lead to faster queries for certain scenarios. However, complex queries involving multiple subclasses may involve more joins and could impact performance.

Cleaning and Maintenance

  • TPH : The single-table approach makes schema updates straightforward. However, as the number of subclasses increases, the table can become cluttered, making maintenance challenging.
  • TPT : The separated-table approach makes schema updates easier for individual subclasses. However, maintaining a large number of tables can be cumbersome.

UML for Users

UML for Users Management

ERDs

TPH : Table Per Hierarchy

TPH

TPT : Table Per Type

TPT

References

About

This repository addresses the challenges of multiple users management and introduces two popular inheritance modelling strategies: TPH (Table Per Hierarchy) and TPT (Table Per Type). The application integrates with IdentityFramework to provide robust user authentication and authorization capabilities .

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages