Argon.Extensions.EntityFrameworkCore 8.5.0
Argon.Extensions.EntityFrameworkCore
Source code generators and utilities for Entity Framework Core.
📦 Installation
dotnet add package Argon.Extensions.EntityFrameworkCore
✨ Features
- Empty constructor generator for EF Core entities
[EmptyConstructible]attribute to automatically generate a protected empty constructor- Useful for entities with parameterized constructors
🚀 Usage
Generating an empty constructor
Entity Framework Core requires entities to have a parameterless constructor. When you have entities with required parameters, this can be problematic. The [EmptyConstructible] attribute solves this by generating a protected parameterless constructor.
using Argon.Extensions.EntityFrameworkCore.Attributes;
[EmptyConstructible]
public partial class User
{
public User(string name, string email)
{
Name = name;
Email = email;
}
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
// A protected empty constructor is automatically generated for EF Core:
// protected User() { }
Important notes
⚠️ The class must be marked as partial for the source generator to work.
The generated constructor is protected, which means:
- Entity Framework Core can use it
- Your domain code cannot accidentally create invalid instances
- You maintain strong constructor constraints in your business logic
📝 API Reference
Attributes
EmptyConstructibleAttribute
Marks a class to have an empty protected constructor generated.
Usage:
[EmptyConstructible]
public partial class MyEntity
{
// Your code here
}
Requirements:
- The class must be
partial - If the class already has an empty constructor, a warning (AREX0001) will be generated
Diagnostics
| Code | Severity | Description |
|---|---|---|
| AREX0001 | Warning | Class already has an empty constructor |
| AREX0002 | Error | Class must be partial |
🔗 Links
No packages depend on Argon.Extensions.EntityFrameworkCore.
.NET Standard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.13.0)