Visium.Anima.EntityFrameworkCore.SourceGeneration 1.0.0-alpha.10

This is a prerelease version of Visium.Anima.EntityFrameworkCore.SourceGeneration.
dotnet add package Visium.Anima.EntityFrameworkCore.SourceGeneration --version 1.0.0-alpha.10
NuGet\Install-Package Visium.Anima.EntityFrameworkCore.SourceGeneration -Version 1.0.0-alpha.10
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Visium.Anima.EntityFrameworkCore.SourceGeneration" Version="1.0.0-alpha.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Visium.Anima.EntityFrameworkCore.SourceGeneration --version 1.0.0-alpha.10
#r "nuget: Visium.Anima.EntityFrameworkCore.SourceGeneration, 1.0.0-alpha.10"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Visium.Anima.EntityFrameworkCore.SourceGeneration as a Cake Addin
#addin nuget:?package=Visium.Anima.EntityFrameworkCore.SourceGeneration&version=1.0.0-alpha.10&prerelease

// Install Visium.Anima.EntityFrameworkCore.SourceGeneration as a Cake Tool
#tool nuget:?package=Visium.Anima.EntityFrameworkCore.SourceGeneration&version=1.0.0-alpha.10&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.

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; }
}
There are no supported framework assets in this package.

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.10 50 4/12/2024
1.0.0-alpha.9 44 4/12/2024
1.0.0-alpha.8 42 4/10/2024
1.0.0-alpha.7 46 4/9/2024
1.0.0-alpha.6 45 4/9/2024
1.0.0-alpha.5 51 4/7/2024
1.0.0-alpha.4 44 4/7/2024