Skip to main content
The Intent.EntityFrameworkCore module provides Entity Framework Core integration for Intent Architect applications. It generates DbContext classes, entity configurations, and all the infrastructure needed to work with relational databases using EF Core.

Overview

This module handles the complete EF Core setup including:
  • DbContext and DbContext interface generation
  • Entity Type Configuration classes
  • Database provider support (SQL Server, PostgreSQL, MySQL, Cosmos DB, Oracle, SQLite)
  • Migration management
  • Connection string configuration
  • Lazy loading proxy support

Installation

Intent.EntityFrameworkCore

Key Components

DbContext Generation

The module generates a DbContext class that:
  • Extends Microsoft.EntityFrameworkCore.DbContext
  • Contains DbSet<T> properties for each entity
  • Configures entity mappings via OnModelCreating
  • Supports custom schema names
  • Handles lazy loading proxies
DbContext Example
public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) 
        : base(options)
    {
    }

    public DbSet<Customer> Customers { get; set; }
    public DbSet<Order> Orders { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.HasDefaultSchema("dbo");
        
        modelBuilder.ApplyConfiguration(new CustomerConfiguration());
        modelBuilder.ApplyConfiguration(new OrderConfiguration());
        
        ConfigureModel(modelBuilder);
    }

    private void ConfigureModel(ModelBuilder modelBuilder)
    {
        // Seed data
        // https://rehansaeed.com/migrating-to-entity-framework-core-seed-data/
    }
}

Entity Type Configuration

For each domain entity, the module generates an IEntityTypeConfiguration<T> implementation:
Configuration Example
public class CustomerConfiguration : IEntityTypeConfiguration<Customer>
{
    public void Configure(EntityTypeBuilder<Customer> builder)
    {
        builder.ToTable("Customers");
        
        builder.HasKey(x => x.Id);
        
        builder.Property(x => x.Name)
            .IsRequired()
            .HasMaxLength(200);
        
        builder.Property(x => x.Email)
            .IsRequired()
            .HasMaxLength(256);
        
        builder.HasMany(x => x.Orders)
            .WithOne(x => x.Customer)
            .HasForeignKey(x => x.CustomerId)
            .OnDelete(DeleteBehavior.Cascade);
    }
}

Configuration Options

Database Settings

Access via: Application Settings → Database Settings
Select the underlying database technology:
  • In Memory - For testing
  • SQL Server - Microsoft SQL Server
  • Cosmos DB - Azure Cosmos DB
  • PostgreSQL - PostgreSQL
  • MySQL - MySQL/MariaDB
  • Oracle - Oracle Database
  • SQLite - SQLite
Default: in-memory
Controls SQL table name generation:
  • Pluralized - Table names are pluralized (Customer → Customers)
  • Singularized - Table names match entity names
  • None - Use entity names as-is
Default: Pluralized
Enables EF Core lazy loading proxies for navigation properties.When enabled:
  • Navigation properties must be virtual
  • Requires Microsoft.EntityFrameworkCore.Proxies NuGet package
  • Lazy loads related entities on first access
Default: true
Exposes a LINQ-capable interface in the Application layer, decoupled from the concrete DbContext.Benefits:
  • Improved testability
  • Separation of concerns
  • Easier to mock in unit tests
Default: false
Sets the UseQuerySplittingBehavior option on the DbContext to SplitQuery.Useful when:
  • Queries include multiple collections
  • Avoiding cartesian explosion
  • Optimizing query performance
Default: false
Enables a convention to convert enums to/from strings in the database.Benefits:
  • More readable database values
  • Easier database querying
  • Better compatibility with other systems
Default: false
Adds SQL table check constraints to ensure data corresponds to the enum.Example:
ALTER TABLE Orders ADD CONSTRAINT CK_Orders_Status 
CHECK (Status IN (0, 1, 2, 3))
Default: false
Explicitly set the default schema name for the application (relational DBs only).Example: dbo, app, publicDefault: Empty (uses database default)
SQL column ordering should reflect the model order.When enabled, properties appear in the database in the same order as in the domain model.Default: false
Controls value generation in EntityTypeConfiguration classes.
  • Default - Let EF Core decide
  • None - Disable value generation
Default: Default
Controls the naming convention of the DBSets created on the DBContext.
  • Pluralized - DbSet names are pluralized
  • Same as Entity - DbSet names match entity names
Default: Pluralized

Database Providers

SQL Server

appsettings.json
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=MyApp;Integrated Security=true"
  }
}
NuGet Packages:
  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.EntityFrameworkCore.Design

PostgreSQL

appsettings.json
{
  "ConnectionStrings": {
    "DefaultConnection": "Host=localhost;Database=myapp;Username=postgres;Password=password"
  }
}
NuGet Packages:
  • Npgsql.EntityFrameworkCore.PostgreSQL
  • Microsoft.EntityFrameworkCore.Design

MySQL

appsettings.json
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Database=myapp;User=root;Password=password"
  }
}
NuGet Packages:
  • Pomelo.EntityFrameworkCore.MySql
  • Microsoft.EntityFrameworkCore.Design

Migrations

The module generates a README in the Migrations folder with instructions:
Add Migration
dotnet ef migrations add InitialCreate --project YourProject.Infrastructure --startup-project YourProject.Api
Update Database
dotnet ef database update --project YourProject.Infrastructure --startup-project YourProject.Api

Interoperability

This module automatically installs companion modules when detected:
  • Intent.DomainEvents → Installs Intent.EntityFrameworkCore.Interop.DomainEvents
  • Intent.Entities → Ensures entity templates are available
  • Intent.AspNetCore.HealthChecks → Adds EF Core health checks

Additional Resources

Build docs developers (and LLMs) love