T1.EfCodeFirstGenerateCli
1.0.22
See the version list below for details.
dotnet add package T1.EfCodeFirstGenerateCli --version 1.0.22
NuGet\Install-Package T1.EfCodeFirstGenerateCli -Version 1.0.22
<PackageReference Include="T1.EfCodeFirstGenerateCli" Version="1.0.22"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="T1.EfCodeFirstGenerateCli" Version="1.0.22" />
<PackageReference Include="T1.EfCodeFirstGenerateCli"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add T1.EfCodeFirstGenerateCli --version 1.0.22
#r "nuget: T1.EfCodeFirstGenerateCli, 1.0.22"
#:package T1.EfCodeFirstGenerateCli@1.0.22
#addin nuget:?package=T1.EfCodeFirstGenerateCli&version=1.0.22
#tool nuget:?package=T1.EfCodeFirstGenerateCli&version=1.0.22
T1.EfCodeFirstGenerateCli
Automatically generate Entity Framework Core Code First classes from your database schema. This MSBuild Task integrates seamlessly with your build process.
Installation
dotnet add package T1.EfCodeFirstGenerateCli
After installation, the code generation task will run automatically during build:
dotnet build
Quick Start
Step 1: Create Connection String Configuration File
Create a .db file in your project root directory (e.g., Test.db):
# Comment lines start with # or //
# SQL Server example
Server=localhost;Database=MyDatabase;User Id=sa;Password=YourPassword;TrustServerCertificate=true
# MySQL example
Server=localhost;Database=TestDb;Uid=root;Pwd=secret;
Supported connection string formats:
- SQL Server: Standard ADO.NET format
- MySQL: MySQL Connector/NET format
Step 2: Build Your Project
The MSBuild Task will automatically scan .db files and generate code during build:
dotnet build
Step 3: Use Generated Code
Generated code will be placed in the Generated/ directory:
Generated/
├── Test.schema # Schema cache file
└── Test/
├── TestDbContext.cs # DbContext
├── Entities/
│ ├── UsersEntity.cs
│ ├── ProductsEntity.cs
│ └── OrdersEntity.cs
└── Configurations/
├── UsersEntityConfiguration.cs
├── ProductsEntityConfiguration.cs
└── OrdersEntityConfiguration.cs
Use the generated code in your application:
using Generated;
using Microsoft.EntityFrameworkCore;
var options = new DbContextOptionsBuilder<TestDbContext>()
.UseSqlServer("your-connection-string")
.Options;
using var context = new TestDbContext(options);
var users = await context.Users.ToListAsync();
Advanced Features
Extend DbContext
Since the generated DbContext is a partial class, you can extend it in another file:
namespace Generated
{
public partial class TestDbContext
{
partial void OnModelCreatingPartial(ModelBuilder modelBuilder)
{
// Add custom configuration
}
}
}
Custom Entity Configuration
All generated EntityConfiguration classes are partial class and provide a ConfigureCustomProperties partial method for adding custom configurations without modifying the auto-generated code.
Example: Create a custom configuration file (e.g., UsersEntityConfiguration.Custom.cs):
namespace Generated.Databases.MyDb.Configurations
{
public partial class UsersEntityConfiguration
{
partial void ConfigureCustomProperties(EntityTypeBuilder<UsersEntity> builder)
{
// Add custom indexes
builder.HasIndex(x => x.Email)
.IsUnique()
.HasDatabaseName("UX_Users_Email");
// Add column comments
builder.Property(x => x.Email)
.HasComment("User email address");
// Define relationships (if navigation properties exist)
builder.HasMany(x => x.Orders)
.WithOne(o => o.User)
.HasForeignKey(o => o.UserId);
}
}
}
Benefits:
- ✅ Custom configuration files are NOT overwritten during regeneration
- ✅ Zero performance overhead (compiler removes unused partial methods)
- ✅ Add indexes, comments, relationships, and other EF Core configurations
- ✅ Type-safe with full IntelliSense support
Note: Avoid overriding auto-generated property configurations in the partial method as this may cause conflicts.
Schema Caching
The .schema file is cached for performance:
- First run: Connects to database and extracts schema
- Subsequent runs: Reads from cache file
When your database structure changes, delete the .schema file to regenerate:
rm Generated/*
dotnet build
Supported Databases
- ✅ SQL Server
- ✅ MySQL / MariaDB
- 🚧 PostgreSQL (planned)
Cross-Platform Support
This package uses Microsoft.Data.SqlClient for SQL Server connectivity, which is fully supported on:
- ✅ Windows
- ✅ macOS
- ✅ Linux
License
MIT License
| 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Build.Utilities.Core (>= 17.14.28)
- Microsoft.Data.SqlClient (>= 5.2.2)
- MySql.Data (>= 8.3.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.30-beta | 149 | 10/31/2025 |
| 1.0.23 | 357 | 10/23/2025 |
| 1.0.22 | 171 | 10/23/2025 |
Fixed cross-platform compatibility by replacing System.Data.SqlClient with Microsoft.Data.SqlClient