CHC.EF.Reverse.Poco
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet tool install --global CHC.EF.Reverse.Poco --version 1.0.0
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local CHC.EF.Reverse.Poco --version 1.0.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=CHC.EF.Reverse.Poco&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package CHC.EF.Reverse.Poco --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EF Core Reverse Engineering Tool
Overview
This project is a dynamic code generator designed to work with .NET 8.0 and Entity Framework 6.0. It provides a command-line interface (CLI) to automate the creation of essential EF components such as:
- POCO Classes: Generate C# classes based on database tables
- Fluent API Configurations: Provide detailed mappings for database schemas
- DbContext: Integrate table operations into a unified context
- Optional UnitOfWork: Manage database transactions and operations efficiently
Features
Architecture & Configuration
- Modern .NET Architecture:
- Built on .NET 8.0
- Leverages
IServiceCollection
for Dependency Injection (DI)
- Flexible Configuration:
- Configure via command line arguments
- Support for
appsettings.json
and custom configuration files - Optional settings for features like pluralization and PascalCase conversion
Multi-Database Support
- Supports both SQL Server and MySQL out of the box
- Easy to extend for additional database providers using
IDatabaseSchemaReader
abstraction
XML Safety and Documentation
- Escaped XML Characters: Ensures generated XML comments are valid
- Multi-line Comment Support: Properly formatted documentation
Code Generation
- Generates properties with accurate data types and constraints
- Supports Data Annotations (e.g.,
Required
,StringLength
) - Outputs well-structured class files for each database table
Installation
Global Tool Installation
Install the tool globally using the .NET CLI:
dotnet tool install --global dotnet-efrev
Required Packages
If you're using the generated code, you'll need:
dotnet add package Microsoft.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package MySql.EntityFrameworkCore
Usage
Initialize Configuration
Create default configuration files:
efrev --init
This will create:
appsettings.json
: Standard .NET configuration fileefrev.json
: Tool-specific configuration file
Basic Usage
Generate code using default settings:
efrev
Command Line Options
Options:
-c, --connection Database connection string
-p, --provider Database provider (SqlServer/MySql)
-n, --namespace Namespace for generated code
-o, --output Output directory
--pluralize Pluralize collection names
--data-annotations Use data annotations
--config Path to custom configuration file
--settings Path to appsettings.json file
--init Initialize configuration files
--help Show help message
Configuration Methods
- Using appsettings.json:
{
"CodeGenerator": {
"ConnectionString": "Server=localhost;Database=YourDb;User Id=YourUser;Password=YourPwd;",
"ProviderName": "Microsoft.Data.SqlClient",
"Namespace": "MyGeneratedApp.Data",
"DbContextName": "MyDbContext",
"UseDataAnnotations": true,
"IncludeComments": true,
"IsPluralize": true,
"OutputDirectory": "./Generated"
}
}
- Using command line:
efrev -c "Server=localhost;Database=YourDb;" -p "Microsoft.Data.SqlClient" -o "./Models"
- Using custom config file:
efrev --config "path/to/efrev.json"
- Mixed approach:
efrev --settings "custom-appsettings.json" --connection "NewConnectionString"
Configuration Priority
- Command line arguments (highest)
- Custom configuration file (efrev.json)
- appsettings.json (lowest)
Example Output
Given a database table Users
, the generator will produce:
POCO Class:
[Table("Users")]
public class User
{
[Key]
public int Id { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
public DateTime CreatedAt { get; set; }
}
Fluent API Configuration:
modelBuilder.Entity<User>(entity => {
entity.ToTable("Users");
entity.HasKey(e => e.Id);
entity.Property(e => e.Name).HasMaxLength(100).IsRequired();
});
Extensibility
- Add New Database Support:
Implement
IDatabaseSchemaReader
for additional database providers - Customize Code Output:
Modify
EntityGenerator
to change the structure or style of generated code
Common Issues and Troubleshooting
Connection Issues
If you encounter connection problems:
- Verify your connection string
- Ensure database provider is correctly specified
- Check database permissions
Configuration Issues
- Make sure configuration files are in the correct location
- Verify JSON syntax in configuration files
- Check file permissions for output directory
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Submit a pull request with your improvements
License
This project is licensed under the MIT License.
Release Notes
- v1.0.0: Initial CLI release
- Added command line interface
- Support for multiple configuration sources
- Improved error handling and feedback
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.