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.
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
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.
- 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
-
Rapid Application Development
- Generate complete data access layers
- Create API endpoints from database schema
- Scaffold CRUD operations
-
Database Documentation
- Generate comprehensive schema documentation
- Visualize table relationships
- Track schema changes
-
Database Migration
- Analyze database dependencies
- Plan migration strategies
- Generate migration scripts
-
Code Generation
- Create strongly-typed entity classes
- Generate data transfer objects (DTOs)
- Build repository interfaces and implementations
-
Architecture Analysis
- Identify circular dependencies
- Analyze table relationships
- Detect common patterns
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.
You will need MSSQL with some database installed. If you need a sample database, feel free to look for the World Wide Importers samples.
Install-Package EzDbSchema.Core// 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"], ... }// 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"
}
}
}
*/// 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();- Configure connection in
EzDbSchema.Cli/appsettings.json:
{
"ConnectionString": "Server=myserver;Database=mydb;User Id=sa;Password=****;TrustServerCertificate=True"
}- Run the CLI:
dotnet EzDbSchema.Cli.dll --schema MySchemaThis will generate MySchema.db.json with the complete schema analysis.
This project was design to be hosted and distributed with nuget.com.
- .net core - The framework used
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Ricky Vega - Initial work - Noctusoft
This project is licensed under the MIT License - see the LICENSE.md file for details
Many thanks to the following projects that have helped in this project
- McMaster.Extensions.CommandLineUtils
- 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
- Nuget package upgrades, updated to .NET 8.0
- Update to Microsoft SqlClient
- Added Server Trust Cert setting
- Nuget package upgrades, updated to .NET 7.0
- Added the ability to tell the generator to not auto create the primary keys if they are missing
- Migration to .NET 6.0