EzDbSchema 9.0.2

dotnet add package EzDbSchema --version 9.0.2                
NuGet\Install-Package EzDbSchema -Version 9.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EzDbSchema" Version="9.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EzDbSchema --version 9.0.2                
#r "nuget: EzDbSchema, 9.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EzDbSchema as a Cake Addin
#addin nuget:?package=EzDbSchema&version=9.0.2

// Install EzDbSchema as a Cake Tool
#tool nuget:?package=EzDbSchema&version=9.0.2                

EZDBSchema - Easy Database Schema

A powerful .NET library that provides comprehensive database schema analysis and code generation capabilities. It allows you to extract complete database schemas including columns, relationships, and advanced features detection, making it perfect for code generation and database documentation tasks.

Key Features

  • Complete Schema Analysis: Extract tables, columns, relationships, and constraints
  • Smart Feature Detection: Automatically identifies common patterns like:
    • Auditable entities (CreatedDate, ModifiedDate)
    • Versioned entities (Version, RowVersion)
    • Soft-deletable entities (IsDeleted, DeletedDate)
    • Composite keys
    • Circular references
  • Dependency Graph Generation: Analyze and visualize table dependencies
  • Code Generation Support: Generate boilerplate code for:
    • ORM entities
    • API controllers
    • Database contexts
    • Repository patterns
  • Multi-Framework Support: Compatible with .NET Standard 2.1, .NET 6.0, 7.0, 8.0, and 9.0
  • Version: 9.0.2

License

This project is licensed under the MIT License - see the LICENSE file for details.

AI Integration

To facilitate AI-powered development and code generation, we provide a comprehensive AI-USAGE.md guide. This documentation is specifically designed to help AI models understand and work with the EzDbSchema library effectively.

AI Documentation Features

  • Core Concepts: Detailed schema structure and class hierarchies
  • Multi-Language Support: Integration details for C#, TypeScript, Python, Go, SQL, and Java
  • ORM Templates: Support for Entity Framework Core, TypeORM, SQLAlchemy, and more
  • API Generation: Templates for REST APIs, GraphQL schemas, and Swagger/OpenAPI
  • Security Features: Authorization, row-level security, and audit trails
  • UI Metadata: Display properties, validation rules, and form generation
  • Advanced Features: Temporal tables, relationships, and performance optimizations

AI models can leverage this documentation to:

  • Generate accurate database-first code
  • Create type-safe entity models
  • Build complete API endpoints
  • Implement proper validation and security
  • Follow best practices for each supported language and framework

Use Cases

  1. Rapid Application Development

    • Generate complete data access layers
    • Create API endpoints from database schema
    • Scaffold CRUD operations
  2. Database Documentation

    • Generate comprehensive schema documentation
    • Visualize table relationships
    • Track schema changes
  3. Database Migration

    • Analyze database dependencies
    • Plan migration strategies
    • Generate migration scripts
  4. Code Generation

    • Create strongly-typed entity classes
    • Generate data transfer objects (DTOs)
    • Build repository interfaces and implementations
  5. Architecture Analysis

    • Identify circular dependencies
    • Analyze table relationships
    • Detect common patterns

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You will need MSSQL with some database installed. If you need a sample database, feel free to look for the World Wide Importers samples.

Using this project:

Installation

Install-Package EzDbSchema.Core

Basic Usage

// Connect to database and get schema
var schema = new EzDbSchema.MsSql.Database().Render(
    "MySchema",
    "Server=myserver;Database=mydb;User Id=sa;Password=****;TrustServerCertificate=True"
);

// Generate code for entities
var codeGen = new DatabaseCodeGenInfo(schema);

// Get required features
var features = codeGen.RequiredFrameworkFeatures;
// Returns: ["Auditing", "Versioning", etc.]

// Get dependency graph
var dependencies = codeGen.DependencyGraph;
// Returns: { "Order": ["Customer", "Product"], ... }

Schema Dump for Handlebars Development

// Get complete schema with all properties
var schema = new EzDbSchema.MsSql.Database().Render("MySchema", connectionString);

// Dump schema to JSON (useful for Handlebars template development)
var schemaJson = Newtonsoft.Json.JsonConvert.SerializeObject(schema, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText("schema.json", schemaJson);

// Available Schema Properties:
/*
{
    "Name": "MySchema",
    "Entities": {
        "TableName": {
            "TableName": "string",
            "Properties": {
                "ColumnName": {
                    "ColumnName": "string",
                    "PropertyName": "string",
                    "IsNullable": "bool",
                    "IsIdentity": "bool",
                    "IsPrimaryKey": "bool",
                    "DataType": "string",
                    "MaxLength": "int",
                    "Precision": "int",
                    "Scale": "int",
                    "HasValidationRules": "bool"
                }
            },
            "Relationships": [
                {
                    "FromTableName": "string",
                    "ToTableName": "string",
                    "FromColumnName": "string",
                    "ToColumnName": "string",
                    "RelationshipName": "string",
                    "Multiplicity": "string"
                }
            ],
            "HasCompositePrimaryKey": "bool",
            "IsAuditable": "bool",
            "IsVersioned": "bool",
            "IsSoftDeletable": "bool"
        }
    }
}
*/

Advanced Features

// Check for specific patterns
var hasAuditableEntities = codeGen.HasAuditableEntities;
var hasVersionedEntities = codeGen.HasVersionedEntities;
var hasSoftDelete = codeGen.HasSoftDeletableEntities;

// Generate API controllers
var apiCode = codeGen.GenerateApiControllers();

// Generate ORM entities
var ormCode = codeGen.GenerateOrmEntities();

CLI Usage

  1. Configure connection in EzDbSchema.Cli/appsettings.json:
{
    "ConnectionString": "Server=myserver;Database=mydb;User Id=sa;Password=****;TrustServerCertificate=True"
}
  1. Run the CLI:
dotnet EzDbSchema.Cli.dll --schema MySchema

This will generate MySchema.db.json with the complete schema analysis.

Deployment

This project was design to be hosted and distributed with nuget.com.

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Many thanks to the following projects that have helped in this project

  • McMaster.Extensions.CommandLineUtils

Release Notes

V 9.0.1 (2025-02-19)

  • Added comprehensive test coverage for DependencyGraph and RequiredFeatures
  • Implemented smart feature detection (Auditing, Versioning, SoftDelete)
  • Enhanced dependency graph generation with support for complex relationships
  • Improved null handling and error resilience
  • Added support for .NET 9.0

V 8.1.0

  • Nuget package upgrades, updated to .NET 8.0
  • Update to Microsoft SqlClient
  • Added Server Trust Cert setting

V 7.0.0

  • Nuget package upgrades, updated to .NET 7.0

V 6.0.1

  • Added the ability to tell the generator to not auto create the primary keys if they are missing

V 6.0.0

  • Migration to .NET 6.0
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on EzDbSchema:

Package Downloads
EzDbCodeGen

This complete and self contained code generation utility will install in a sub directory EzDbCodeGen of a target project. From this path, you can run a powershell script that will generate code based on the connection string. Each template is a handlebars template that has tags that specify where you would like to output the generated code and if there is a vs project that you wish to update with the file list (old VS project formats only).

EzDbCodeGen.Core

This will install a local cli tool. From this path, you can run a powershell script that will generate code based on the connection string. Each template is a handlebars template that has tags that specify where you would like to output the generated code and if there is a vs project that you wish to update with the file list (old VS project formats only).

EzDbSchema.MsSql

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.2 40 2/19/2025
9.0.1 26 2/19/2025
8.2.0 169 8/26/2024
8.0.2 161 3/17/2024
8.0.1 120 3/17/2024
8.0.0 129 3/17/2024
7.0.0 412 1/2/2023
6.0.1 801 4/27/2022
6.0.0 6,720 11/23/2021
5.0.9 402 9/7/2021
5.0.8 351 9/6/2021
5.0.7 463 6/20/2021
1.0.53 1,180 5/13/2020
1.0.31 1,925 12/21/2019
1.0.29 582 8/30/2019
1.0.28 1,617 6/6/2019
1.0.27 602 6/5/2019
1.0.26 816 2/22/2019
1.0.23 901 8/24/2018
1.0.22 842 8/20/2018
1.0.21 895 8/16/2018
1.0.16 875 8/1/2018
1.0.15 899 7/27/2018
1.0.11 5,693 7/20/2018

Added smart feature detection, dependency graph generation, and improved schema analysis capabilities.