Skip to main content
The application uses Entity Framework Core with SQL Server for data persistence, implementing a code-first approach with fluent API configurations.

ApplicationDbContext

The ApplicationDbContext is the main database context inheriting from IdentityDbContext:
// persistenDatabase/ApplicationDbContext.cs:9
public class ApplicationDbContext :
    IdentityDbContext<IdentityUser, IdentityRole, string>
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
    : base(options)
    {
    }

    public DbSet<Category> Categories { get; set; }
    public DbSet<Master> Masters { get; set; }
    public DbSet<BiddingParticipant> BiddingParticipants { get; set; }
    public DbSet<PQRSD> PQRSDs { get; set; }
    public DbSet<FileDocument> FileDocuments { get; set; }
    public DbSet<Document> Documents { get; set; }
    public DbSet<Product> Products { get; set; }
    public DbSet<Employee> Employees { get; set; }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        new CategoryConfig(builder.Entity<Category>());
        new BiddingParticipantConfig(builder.Entity<BiddingParticipant>());
        new MasterConfig(builder.Entity<Master>());
        new DocumentConfig(builder.Entity<Document>());
        new FileDocumentConfig(builder.Entity<FileDocument>());
        new PQRSDConfig(builder.Entity<PQRSD>());
        new ProductConfig(builder.Entity<Product>());
        new EmployeeConfig(builder.Entity<Employee>());
    }
}
The context extends IdentityDbContext to include ASP.NET Core Identity tables for authentication and authorization.

Database Schema Diagram

Core Entities

Represents service categories displayed on the website.
// model/Category.cs:9
public class Category
{
    public int Id { get; set; }
    public string NameCategory { get; set; }
    public string UrlCategory { get; set; }
    
    [AllowHtml]
    [DataType(DataType.MultilineText)]
    public string Description { get; set; }
    
    public string CoverPage { get; set; }
    public bool Statud { get; set; }
    public DateTime DateCreate { get; set; }
    public DateTime DateUpdate { get; set; }
}
Configuration (persistenDatabase/Config/CategoryConfig.cs:11):
public CategoryConfig(EntityTypeBuilder<Category> entityBuilder)
{
    entityBuilder.HasKey(x => x.Id);
    entityBuilder.Property(x => x.NameCategory).IsRequired();
    entityBuilder.Property(x => x.Description).IsRequired();
}

Entity Configuration Pattern

Entity configurations are separated into individual classes for maintainability:
// Example: persistenDatabase/Config/ProductConfig.cs
public class ProductConfig
{
    public ProductConfig(EntityTypeBuilder<Product> entityBuilder)
    {
        // Primary Key
        entityBuilder.HasKey(x => x.ProductId);

        // Required fields
        entityBuilder.Property(x => x.Name).IsRequired();
        entityBuilder.Property(x => x.Description).IsRequired();

        // Optional: String lengths, relationships, etc.
    }
}
This pattern provides:
  • Separation of concerns: Configuration separate from entities
  • Reusability: Configurations can be composed
  • Testability: Can be unit tested independently
  • Maintainability: Easy to locate and modify

Identity Integration

The database includes ASP.NET Core Identity tables:
  • AspNetUsers: User accounts
  • AspNetRoles: User roles
  • AspNetUserRoles: User-role mappings
  • AspNetUserClaims: User claims
  • AspNetUserLogins: External login providers
  • AspNetUserTokens: Authentication tokens
  • AspNetRoleClaims: Role-based claims
// ApplicationDbContext inherits Identity tables
public class ApplicationDbContext :
    IdentityDbContext<IdentityUser, IdentityRole, string>

Connection Configuration

Database connection is configured in Startup.cs:28:
services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlServer(
        Configuration.GetConnectionString("DefaultConnection")));
Connection string example in appsettings.json:
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=ESPSantaFeDB;Trusted_Connection=True;MultipleActiveResultSets=true"
  }
}

Migrations

Entity Framework Core migrations manage database schema:
# Create a new migration
dotnet ef migrations add MigrationName

# Update database
dotnet ef database update

# Generate SQL script
dotnet ef migrations script
Migrations are stored in persistenDatabase/Migrations/.

Best Practices Implemented

Code-First Approach

Entities defined in C# with migrations generating the database schema

Fluent API

Entity configurations using Fluent API for explicit control

Navigation Properties

Proper relationships with navigation properties for EF Core

Validation

Data annotations for validation and constraints

Next Steps

Services Layer

Learn how services interact with the database

API Reference

Explore the data models and DTOs

Controllers

See how controllers use the database

Authentication

Review Identity database tables

Build docs developers (and LLMs) love