Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EntityClassGenerator

Version: 1.0.0
Status: Production Ready 🚀

.NET 10 WPF desktop application that reverse-engineers SQL Server, MySQL, PostgreSQL, and SQLite databases into Entity Framework Core entities, DbContext, and Fluent API configurations.

Successor to pyPOCO with a single-process, WPF-native design, first-class EF Core output, and a modern 5-step wizard UX.

✨ Key Features:

  • 🔄 Reverse-engineer SQL Server, MySQL, PostgreSQL, and SQLite databases to EF Core entities
  • 🎨 Modern WPF UI with Fluent design (Mica, themes, wizard)
  • 💾 Recent connections & saved profiles
  • 🎯 Smart naming conventions (PascalCase, camelCase, snake_case)
  • ⚙️ Fluent API configurations for complex mappings
  • 🔍 Real-time syntax-highlighted C# preview

Status

Phase Scope Status
0 Foundations (solution, CPM, CI, DI host, arch tests) ✅ complete
1 Vertical slice: connect → list tables → generate one entity to disk ✅ complete
2 Full metadata & type mapping ([Key], [DatabaseGenerated], FK loading, composite-PK warning) ✅ complete
3 Naming engine polish (namespace styling, extra Roslyn compile coverage) ✅ complete
UI WPF-UI Fluent chrome (Mica, dark/light/system theme, brand accent, multi-select tables, filter, schema selector) ✅ complete
4 Templates + DbContext + Fluent configs (hand-rolled StringBuilder) ✅ complete
5 Wizard UX (5 steps: Connection → Tables → Naming → Output → Preview with AvalonEdit) ✅ complete
6 Existing-file protection (create/update/skip, partial classes) ⏭️ skipped
7 Recent connections, saved profiles, generation history ✅ complete
8 Hardening & release (packaging, distribution, docs) ✅ complete

116/116 unit tests pass. Build is clean (0 warnings, 0 errors).

📦 Download & Installation

For End Users

Three distribution packages are available:

Package Size Installation Best For
Portable ZIP 82 MB None (extract & run) Testing, USB drives, network shares
Inno Setup Installer 56 MB Traditional wizard Permanent installations, enterprises
MSIX Package 81 MB Modern one-click Microsoft Store, managed environments

Download: See Releases page for latest downloads.

SHA-256 Checksums: Available in publish/CHECKSUMS.md for package verification.

Quick Install Guide

Option 1: Portable (Recommended for Quick Start)

# No installation required!
1. Download EntityClassGenerator-v1.0.0-Portable-win-x64.zip
2. Extract to any folder (e.g., C:\Tools\EntityClassGenerator)
3. Run EntityClassGenerator.App.exe

Option 2: Installer (Recommended for Permanent Use)

# Traditional Windows installation
1. Download EntityClassGenerator-v1.0.0-Setup.exe
2. Double-click to run installer
3. Follow installation wizard
4. Launch from Start Menu: "Entity Class Generator"

# Silent installation (IT admins):
EntityClassGenerator-v1.0.0-Setup.exe /VERYSILENT /NORESTART

Option 3: MSIX (For Store/Enterprise)

# Modern Windows packaging
1. Download EntityClassGenerator-v1.0.0-Setup.msix
2. Double-click to install
3. Trust certificate if prompted (first-time only)
4. Launch from Start Menu

📚 Complete installation guide: DISTRIBUTION.md


🛠️ Building from Source

Prerequisites

Required (Development):

  • Windows 10/11 (x64)
  • .NET 10 SDK - Download
    • Pinned via global.json in repository
  • One supported database engine:

Optional (For Building Installers):

  • Inno Setup 6.x - Download (free)
    • Required for building .exe installer
    • Install with default options
  • Windows SDK - Download
    • Required for building MSIX package
    • Includes makeappx.exe and signtool.exe

Clone & Build

# Clone repository
git clone https://github.com/yourusername/EntityClassGenerator.git
cd EntityClassGenerator

# Restore dependencies
dotnet restore EntityClassGenerator.slnx

# Build (Debug)
dotnet build EntityClassGenerator.slnx

# Build (Release)
dotnet build EntityClassGenerator.slnx -c Release

# Run tests (80 unit tests)
dotnet test EntityClassGenerator.slnx

# Run application
dotnet run --project src\EntityClassGenerator.App

Build Distribution Packages

1️⃣ Build Portable ZIP

# No additional tools required - just .NET SDK
.\Build-Portable.ps1

# Output: publish/EntityClassGenerator-v1.0.0-Portable-win-x64.zip (82 MB)
# Contains: Self-contained .NET runtime, all dependencies, 544 files

2️⃣ Build Inno Setup Installer

# Prerequisite: Install Inno Setup 6.x from https://jrsoftware.org/isdl.php

.\Build-InnoSetup.ps1

# Output: publish/EntityClassGenerator-v1.0.0-Setup.exe (56 MB)
# Features: Start Menu shortcuts, desktop icon, uninstaller, silent install

3️⃣ Build MSIX Package

# Prerequisite: Install Windows SDK from https://developer.microsoft.com/windows/downloads/windows-sdk/

.\Build-MSIX.ps1

# Output: publish/EntityClassGenerator-v1.0.0-Setup.msix (81 MB)
# Features: Modern packaging, auto-update support, Store-compatible

# Optional: Sign with test certificate
.\Build-MSIX.ps1 -Sign

Verify Builds

# Check build outputs
dir publish

# Verify checksums
cd publish
Get-FileHash *.zip, *.exe, *.msix -Algorithm SHA256

📚 Complete build & packaging guide: DISTRIBUTION.md


🚀 Quick Start (After Installation)

  1. Launch the application
  2. Connection (Step 1): Choose a database engine and enter connection details
    • Engine: SQL Server, MySQL, PostgreSQL, or SQLite
    • Server/Database/Auth for server-based engines, or file path for SQLite
    • SQL Server only: use Find Servers to discover visible instances
    • SQL Server/MySQL/PostgreSQL: use Load Databases after entering server credentials
    • Click "Test Connection"
  3. Tables (Step 2): Select tables to generate
    • Filter by schema
    • Use checkboxes to select tables
    • "Select All Visible" for bulk selection
  4. Naming (Step 3): Configure naming conventions
    • Choose case style: PascalCase, camelCase, snake_case
    • Enable "Singularize class names" (recommended)
    • Save as profile for reuse
  5. Output (Step 4): Choose output directory
    • Select folder for generated files
    • Enable "Use Fluent API" for advanced mappings
  6. Preview (Step 5): Review & generate
    • Syntax-highlighted C# preview
    • Click "Generate" to create files

Result: Entity classes, DbContext, and Fluent configurations in your output folder!


📂 Repository Structure

EntityClassGenerator/
├── src/
│   ├── EntityClassGenerator.Core/         # Domain models, interfaces, business rules
│   │   ├── Models/                        # TableInfo, ColumnInfo, ForeignKeyInfo, etc.
│   │   ├── Abstractions/                  # Interfaces (IEntityGenerator, etc.)
│   │   ├── Generation/                    # Code generators (Entity, DbContext, Fluent)
│   │   ├── Naming/                        # Naming conventions engine
│   │   └── TypeMapping/                   # SQL → C# type mapping
│   ├── EntityClassGenerator.Infrastructure/ # Persistence, SQL metadata, file I/O
│   │   ├── SqlServer/                     # SQL Server metadata + server discovery
│   │   ├── MySql/                         # MySQL metadata reader
│   │   ├── PostgreSql/                    # PostgreSQL metadata reader
│   │   ├── Sqlite/                        # SQLite metadata reader
│   │   ├── FileSystem/                    # File writing services
│   │   └── Persistence/                   # JSON stores (connections, profiles)
│   ├── EntityClassGenerator.App/          # WPF UI, MVVM, DI host
│   │   ├── ViewModels/                    # MainViewModel, WizardViewModel
│   │   ├── Views/                         # WizardView, Step1-5 UserControls
│   │   ├── Converters/                    # XAML value converters
│   │   └── App.xaml.cs                    # DI container setup
│   └── EntityClassGenerator.Tests/        # Unit & architecture tests (xUnit)
│       ├── Generation/                    # Generator tests
│       ├── TypeMapping/                   # Type parser and mapper tests
│       ├── Infrastructure/                # Infrastructure behavior tests
│       └── Architecture/                  # Layer boundary tests
├── packaging/                             # Distribution packaging
│   ├── innosetup/                        # Inno Setup installer script
│   └── msix/                             # MSIX package manifest
├── publish/                               # Build outputs (generated)
│   ├── EntityClassGenerator-v1.0.0-Portable-win-x64.zip
│   ├── EntityClassGenerator-v1.0.0-Setup.exe
│   └── EntityClassGenerator-v1.0.0-Setup.msix
├── Build-Portable.ps1                     # Build portable ZIP
├── Build-InnoSetup.ps1                    # Build installer
├── Build-MSIX.ps1                         # Build MSIX package
├── README.md                              # This file
├── DISTRIBUTION.md                        # Complete packaging guide
├── RELEASE_NOTES.md                       # v1.0.0 release notes
└── EntityClassGenerator.slnx              # Solution file (.NET 10)

🧪 Testing

Run All Tests

# Run full test suite (116 tests)
dotnet test EntityClassGenerator.slnx

# Run with detailed output
dotnet test EntityClassGenerator.slnx --verbosity detailed

Run Specific Test Categories

# Architecture tests (layer boundaries)
dotnet test --filter FullyQualifiedName~ArchitectureTests

# Entity generator tests (Roslyn compile verification)
dotnet test --filter FullyQualifiedName~EntityGeneratorTests

# DbContext & Fluent API tests
dotnet test --filter FullyQualifiedName~DbContextAndFluentTests

# Naming converter tests
dotnet test --filter FullyQualifiedName~NameConverterTests

Test Coverage

  • 116/116 tests passing
  • Roslyn compile verification - All generated code compiles against EF Core 9.0
  • Architecture tests - Enforces layer boundaries (Core/Infrastructure don't reference WPF)
  • Golden file tests - Deterministic output verification

🔧 Development Workflow

Running the App Locally

# Run from command line
dotnet run --project src\EntityClassGenerator.App

# Or open in Visual Studio 2022 / Rider and F5 to debug

Making Changes

# 1. Create feature branch
git checkout -b feature/my-new-feature

# 2. Make changes and test
dotnet build
dotnet test

# 3. Ensure no warnings
dotnet build EntityClassGenerator.slnx --warnaserror

# 4. Commit and push
git commit -m "Add new feature"
git push origin feature/my-new-feature

Code Quality

  • Zero warnings policy - Build configured with TreatWarningsAsErrors
  • CA analyzers - Microsoft.CodeAnalysis.NetAnalyzers enforced
  • EditorConfig - Consistent formatting across editors
  • Nullable reference types - #nullable enable throughout

Features (current)

Generation

  • SQL Server, MySQL, PostgreSQL, and SQLite → EF Core entity classes (one file per table).
  • Independent naming conventions for class, namespace, property, and file (Pascal / camel / snake / preserve). Namespace convention is applied per dotted segment, with reserved-word segments (class, namespace, …) automatically @-escaped.
  • Entity annotations: #nullable enable, [Table("...")], [Column("...")], [Display(Name="...", Order=pos*10)], [Required], [StringLength(n)], [Key], [DatabaseGenerated(Identity)], [DatabaseGenerated(Computed)].
  • Navigation properties — FK-side reference (nullable when all local columns are nullable) plus inverse ICollection<T> on the referenced entity.
  • NRT-aware: non-nullable reference-type properties are initialized with = null!;.
  • Composite / missing PKs surface as generation warnings and are handled by the Fluent generator (HasKey / HasNoKey).
  • DbContext generation — a partial class with one DbSet<T> per selected table (deterministic order) and OnModelCreating calling ApplyConfigurationsFromAssembly.
  • Fluent IEntityTypeConfiguration<T> — emitted per table when needed: ToTable(name, schema) for non-default schemas (dbo/public/main), HasKey(x => new { … }) for composite PKs, HasNoKey for keyless entities, HasPrecision(p, s) for decimal columns, and HasOne(...).WithMany(...).HasForeignKey(...).OnDelete(...) for every foreign key.
  • All output is Roslyn parse- and compile-verified against EF Core 9.0.0 + Relational in the test suite.

Metadata

  • SQL Server sys.* reader, MySQL/PostgreSQL information_schema readers, and SQLite PRAGMA reader (async, cancellable).
  • Loads schemas, tables, columns (nullable, identity, computed, precision/scale, defaults), primary keys, and foreign keys (grouped by constraint, ordered, cascade-delete flag) across all supported engines.

UI (WPF + WPF-UI)

  • 5-step wizard flow: Connection → Tables → Naming → Output → Preview
    • Step indicator with visual feedback (active / completed / pending)
    • Per-step validation guarding Next/Generate buttons
    • Back/Next navigation preserved across steps
    • SQL Server instance discovery via Find Servers
    • SQL Server/MySQL/PostgreSQL database enumeration via Load Databases
    • SQLite file selection via Browse…
  • Recent Connections (Phase 7) — dropdown with last 10 used connections, auto-populated on select
  • Saved Profiles (Phase 7) — save/load naming conventions and settings, with 2 built-in profiles ("EF Core Standard", "Preserve Names")
  • AvalonEdit preview — syntax-highlighted C# code (Entity, DbContext, Fluent config snippets) with // File: ... headers
  • Fluent-design FluentWindow with Mica backdrop and custom title bar.
  • Theme selector: System / Light / Dark. System uses SystemThemeWatcher to follow OS changes live.
  • Brand palette: primary accent #00B3F0 (cyan), secondary #A6CE39 (green), tertiary #F37021 (orange). Applied via ApplicationAccentColorManager.
  • Multi-select tables DataGrid with checkbox column, live text filter, schema selector, and Select all / Clear / Invert buttons.
  • Batch generation with progress bar, cancellation, and activity log.

Understanding Fluent API Configurations

When you enable "Use Fluent API" in Step 3 (Naming), the generator creates additional *Configuration.cs files in a Configurations/ subdirectory. These files use EF Core's Fluent API to configure advanced entity mappings that can't be expressed with simple data annotations.

What are Configuration files?

Fluent API Configuration files are classes that implement IEntityTypeConfiguration<T>. They provide a clean, centralized way to configure how EF Core maps your entities to database tables.

Example:

// Configurations/OrderConfiguration.cs
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace YourNamespace;

public class OrderConfiguration : IEntityTypeConfiguration<Order>
{
    public void Configure(EntityTypeBuilder<Order> builder)
    {
        builder.ToTable("Orders", "sales");
        
        builder.HasKey(x => new { x.OrderId, x.LineNumber }); // Composite PK
        
        builder.Property(x => x.TotalAmount)
               .HasPrecision(18, 2); // Decimal precision
        
        builder.HasOne(x => x.Customer)
               .WithMany(x => x.Orders)
               .HasForeignKey(x => x.CustomerId)
               .OnDelete(DeleteBehavior.Cascade);
    }
}

When are they generated?

Configuration files are only created when needed. A table gets a configuration file if it has:

  • Composite primary key (HasKey(x => new { ... }))
  • No primary key (HasNoKey() for views/queries)
  • Non-dbo schema (ToTable(name, schema))
  • Decimal columns with precision/scale (HasPrecision(p, s))
  • Foreign key relationships (HasOne/WithMany/HasForeignKey)

Simple tables with a single integer PK in the dbo schema get no configuration file - they use data annotations only.

How does EF Core find them?

Your DbContext automatically discovers and applies all configurations via:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);
}

This scans the assembly for all IEntityTypeConfiguration<T> classes and applies them automatically. You don't need to manually register each one.

Why use Fluent API instead of Data Annotations?

Scenario Data Annotations Fluent API
Simple PK [Key] HasKey(x => x.Id)
Composite PK ❌ Not possible HasKey(x => new { x.A, x.B })
String length [StringLength(50)] HasMaxLength(50)
Decimal precision ❌ Not possible HasPrecision(18, 2)
Foreign keys ⚠️ Limited ✅ Full control (cascade, restrict, etc.)
Schema mapping [Table("T", Schema="s")] ToTable("T", "s")

Fluent API advantages:

  • Keeps entity classes clean - no attribute clutter
  • More powerful - can express complex scenarios
  • Better separation - entities focus on domain logic, configs focus on persistence
  • Easier to maintain - all DB mapping in one place per entity

What if I don't want them?

Option 1: Uncheck "Use Fluent API" in Step 3 (Naming). The generator will use data annotations only.

Option 2: Delete the Configurations/ folder and remove the ApplyConfigurationsFromAssembly call from your DbContext. Then manually configure everything via attributes on your entity classes.

⚠️ Warning: Some scenarios (composite keys, decimal precision) cannot be configured with attributes alone. If you disable Fluent API, you'll need to manually add configuration code to OnModelCreating for these cases.

Learn more

📖 Documentation

Document Description
README.md This file - project overview, build, and installation
DISTRIBUTION.md Complete packaging and distribution guide
RELEASE_NOTES.md v1.0.0 release notes and feature highlights
project-instructions.md Original product specification
BUILD_SUCCESS.md Build session summary
PACKAGING_SUMMARY.md Packaging work details
publish/CHECKSUMS.md SHA-256 checksums for packages

🏗️ Architecture

Clean Architecture Layers

┌─────────────────────────────────────┐
│  EntityClassGenerator.App           │  ← WPF UI, ViewModels, DI host
│  (Presentation Layer)               │
└────────────┬────────────────────────┘
             │ references
             ▼
┌─────────────────────────────────────┐
│  EntityClassGenerator.Infrastructure│  ← SQL metadata, file I/O, persistence
│  (Infrastructure Layer)             │
└────────────┬────────────────────────┘
             │ references
             ▼
┌─────────────────────────────────────┐
│  EntityClassGenerator.Core          │  ← Domain models, interfaces, generators
│  (Domain Layer - no dependencies)   │
└─────────────────────────────────────┘

Architectural Guardrails

Enforced by ArchitectureTests:

  • Core and Infrastructure never reference WPF assemblies
    • No PresentationCore, PresentationFramework, WindowsBase, or WPF-UI
    • Ensures domain logic is UI-agnostic
  • ✅ WPF-specific code lives exclusively in App project
  • ✅ Dependency flow: App → Infrastructure → Core (never reversed)

Key Design Patterns

  • MVVM (Model-View-ViewModel) - via CommunityToolkit.Mvvm
  • Dependency Injection - Microsoft.Extensions.DependencyInjection
  • Repository Pattern - IDatabaseMetadataReader, IFileWriter
  • Strategy Pattern - IEntityGenerator, ITypeMapper
  • Observer Pattern - INotifyPropertyChanged, ObservableCollection<T>

🛠️ Technology Stack

Category Technology Version
Runtime .NET 10.0
UI Framework WPF Built-in
UI Library WPF-UI 4.0.3
Code Editor AvalonEdit 6.4.0
MVVM CommunityToolkit.Mvvm 8.4.0
Database Microsoft.Data.SqlClient 6.1.0
Dependency Injection Microsoft.Extensions.DependencyInjection 10.0
Logging Microsoft.Extensions.Logging 10.0
Configuration Microsoft.Extensions.Configuration 10.0
Testing xUnit 2.9.3
Roslyn Microsoft.CodeAnalysis.CSharp 4.12.0

🤝 Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Write tests for new functionality
  4. Ensure all tests pass (dotnet test)
  5. Ensure no build warnings (dotnet build --warnaserror)
  6. Commit changes (git commit -m 'Add amazing feature')
  7. Push to branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Code Style

  • Follow existing code conventions (EditorConfig)
  • Use meaningful variable names
  • Add XML documentation for public APIs
  • Keep methods focused and testable

📜 License

Open Source - See LICENSE file for details.


🙏 Acknowledgments

Built with amazing open-source libraries:

Special thanks to the .NET and EF Core teams for excellent tooling!


📞 Support & Links


🎯 Roadmap

v1.0 ✅ (Current)

  • SQL Server reverse engineering
  • MySQL reverse engineering
  • PostgreSQL reverse engineering
  • SQLite reverse engineering
  • EF Core entity generation
  • DbContext generation
  • Fluent API configurations
  • 5-step wizard UI
  • Recent connections & profiles
  • Distribution packages
  • SQL Server server discovery
  • Server database listing (SQL Server/MySQL/PostgreSQL)

v2.0 (Future)

  • Repository pattern generation
  • Unit test scaffolding
  • CLI mode (headless operation)
  • Azure AD / Entra ID authentication

Made with ❤️ using .NET 10, WPF, and Entity Framework Core

Last updated: 2026-08-04

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages