Adding a New Entity: Teacher
Understanding Core Entity Architecture, Primary Keys, and Automatic Base Fields in AUA
The Concept of Entity in AUA Framework
Entities sit at the heart of the AUA framework architecture. Each entity is defined by a class that encapsulates its properties, characteristics, and relationships with other entities. Every entity relies on an identifier that can be any allowed .NET data type, or even a composite primary key consisting of two or more data types combined.
Inheritance & Identifiers
-
Every entity inherits from the base
DomainEntityclass. -
This base class automatically injects a primary key field called
IDalongside audit/monitoring fields. -
Primary keys can easily be configured for types other than
int, such aslongor custom combination keys.
Default Built-in Fields
By default, the framework automatically handles specific operational fields for each entity:
The primary record identifier with customizable data types.
Indicates whether the entity record is active or inactive in the system.
Automatically generated inside SQL Server to track creation time without manual payload entry.
2. Composite Primary Key Configuration (UserRoleConfig)
For intermediate join tables in Many-to-Many relationships, the single Id property is ignored, and a compound primary key is defined using multiple foreign keys.
public class UserRoleConfig : IEntityTypeConfiguration<UserRole>
{
public void Configure(EntityTypeBuilder<UserRole> builder)
{
// Ignore default single Id property
builder.Ignore(p => p.Id);
// Define composite key combining AppUserId and RoleId
builder.HasKey(p => new
{
p.AppUserId,
p.RoleId
});
}
}
"If you think good architecture is expensive, try bad architecture."AUA Framework Philosophy