Visium.Anima.EntityFrameworkCore.SourceGeneration
1.0.0-alpha.12
See the version list below for details.
dotnet add package Visium.Anima.EntityFrameworkCore.SourceGeneration --version 1.0.0-alpha.12
NuGet\Install-Package Visium.Anima.EntityFrameworkCore.SourceGeneration -Version 1.0.0-alpha.12
<PackageReference Include="Visium.Anima.EntityFrameworkCore.SourceGeneration" Version="1.0.0-alpha.12" />
<PackageVersion Include="Visium.Anima.EntityFrameworkCore.SourceGeneration" Version="1.0.0-alpha.12" />
<PackageReference Include="Visium.Anima.EntityFrameworkCore.SourceGeneration" />
paket add Visium.Anima.EntityFrameworkCore.SourceGeneration --version 1.0.0-alpha.12
#r "nuget: Visium.Anima.EntityFrameworkCore.SourceGeneration, 1.0.0-alpha.12"
#:package Visium.Anima.EntityFrameworkCore.SourceGeneration@1.0.0-alpha.12
#addin nuget:?package=Visium.Anima.EntityFrameworkCore.SourceGeneration&version=1.0.0-alpha.12&prerelease
#tool nuget:?package=Visium.Anima.EntityFrameworkCore.SourceGeneration&version=1.0.0-alpha.12&prerelease
Anima.EntityFrameworkCore.SourceGeneration
Source generators to reduce boilerplate code when working with EntityFrameworkCore.
GenerateDbSets
This feature eases the burden of manually adding entities to the DbContext every time a new entity
class is created.
Usage
Set the project's DbContext class as partial and mark it with the [GenerateDbSets]
attribute to automatically generate DbSet properties for every class
in the project that implements IEntityTypeConfiguration.
For classes that don't need to implement IEntityTypeConfiguration, the IEntity marker interface from the
Anima.EntityFrameworkCore namespace can be implemented instead to mark the class for DbSet generation.
Example
Given the following classes:
[GenerateDbSets]
public partial class DatabaseContext : DbContext
{
public DatabaseContext() { } // Parameterless constructor for dotnet ef
public DatabaseContext(DbContextOptions<DatabaseContext> options)
{
// Configure the database here
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Add entity configurations from classes that implement IEntityTypeConfiguration
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetAssembly(typeof(DatabaseContext))!);
base.OnModelCreating(modelBuilder);
}
}
public class User : IEntityTypeConfiguration<User>
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public ICollection<Session> Sessions { get; set; } = new HashSet<Session>();
public void Configure(EntityTypeBuilder<User> builder)
{
builder.Property(e => e.FirstName).HasMaxLength(50);
builder.Property(e => e.LastName).HasMaxLength(50);
}
}
public class Session : IEntityTypeConfiguration<User>
{
public int Id { get; set; }
public User User { get; set; }
public int UserId { get; set; }
public string Platform { get; set; }
public DateTime LoginTime { get; set; }
public DateTime? LogoutTime { get; set; }
public void Configure(EntityTypeBuilder<User> builder)
{
builder.Property(e => e.Platform).HasMaxLength(20);
}
}
This output will be generated:
public partial class DatabaseContext
{
public DbSet<User> Users { get; set; }
public DbSet<Session> Sessions { get; set; }
}
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
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.0-alpha.16 | 130 | 8/18/2025 |
| 1.0.0-alpha.15 | 156 | 4/24/2025 |
| 1.0.0-alpha.14 | 164 | 4/24/2025 |
| 1.0.0-alpha.13 | 156 | 4/24/2025 |
| 1.0.0-alpha.12 | 159 | 4/3/2025 |
| 1.0.0-alpha.11 | 99 | 7/15/2024 |
| 1.0.0-alpha.10 | 105 | 4/12/2024 |
| 1.0.0-alpha.9 | 91 | 4/12/2024 |
| 1.0.0-alpha.8 | 102 | 4/10/2024 |
| 1.0.0-alpha.7 | 97 | 4/9/2024 |
| 1.0.0-alpha.6 | 103 | 4/9/2024 |
| 1.0.0-alpha.5 | 110 | 4/7/2024 |
| 1.0.0-alpha.4 | 103 | 4/7/2024 |