View on GitHub
Clean Architecture Toolkit for .NET
Clean Architecture Toolkit is a clean, modular architecture foundation for .NET applications.
It embraces SOLID principles and focuses on maintainability, testability, and scalability through clear boundaries and pluggable design.

|   HOME   |   MODULE OVERVIEW   |   DEMO   |

Cat.EFCore

Set up Entity Framework Core entities the same way every time.
Inherit from a base class, call one extension method in OnModelCreating, and get a Guid key, an identity sequence column, and optional temporal tables.

Table of contents

NuGet packages

NuGet Version

Package Role Install Downloads
Cat.EFCore.Entities Entity base classes dotnet add package gmarginet.Cat.EFCore.Entities NuGet Downloads
Cat.EFCore.Extensions Model builder extensions dotnet add package gmarginet.Cat.EFCore.Extensions NuGet Downloads

Namespaces

Namespace What it holds
Cat.EFCore.Entities Base classes for regular, temporal and reference data entities.
Cat.EFCore.Extensions Model builder extensions that configure keys, indexes and tables for the base classes.

Dependencies

Cat.EFCore has no dependencies on other CAT modules.

Usage

Inherit your entities from the Cat base classes.

public class Todo : CatEntityBase
{
    public string Title { get; set; } = string.Empty;
    public Guid TodoOwnerId { get; set; }
    public TodoOwner? TodoOwner { get; set; }
}

public class TodoHistoryItem : CatTemporalEntityBase
{
    public string Title { get; set; } = string.Empty;
}

// The table belongs to another service that shares the database.
public class TodoOwner : CatReferenceEntityBase
{
    public string Name { get; set; } = string.Empty;
}

Configure them in OnModelCreating.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.ConfigureCatEntity<Todo>("Todo", "todo");
    modelBuilder.ConfigureCatTemporalEntity<TodoHistoryItem>("TodoHistoryItem", "todo");
    modelBuilder.ConfigureCatReferenceEntity<TodoOwner>("TodoOwner", "identity");

    modelBuilder.Entity<Todo>()
        .HasOne(t => t.TodoOwner)
        .WithMany()
        .HasForeignKey(t => t.TodoOwnerId);
}

What you get:

When to use CatReferenceEntityBase

Use it for a table that someone else owns, so you can point a foreign key at it.

Do not use it for your own tables. Use CatEntityBase for those, even when the data is a short list of fixed values.