A powerful .NET library for database schema analysis and code generation. Extract complete database schemas, detect patterns, generate dependency graphs, and scaffold code.
$ dotnet add package EzDbSchemaA 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.
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.
AI models can leverage this documentation to:
Rapid Application Development
Database Documentation
Database Migration
Code Generation
Architecture Analysis
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();EzDbSchema.Cli/appsettings.json:{
"ConnectionString": "Server=myserver;Database=mydb;User Id=sa;Password=****;TrustServerCertificate=True"
}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.
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.
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