SpatialFocus / EntityFrameworkCore.Extensions

A set of useful extensions for EntityFrameworkCore (Enum Lookup Tables, Naming of tables / properties / keys, Pluralize).
MIT License
23 stars 11 forks source link
code-generation dotnetstandard efcore utilities

SpatialFocus.EntityFrameworkCore.Extensions

A set of useful extensions for EntityFrameworkCore (Enum Lookup Tables, Naming of tables / properties / keys, Pluralize).

Build / Publish NuGet NuGet FOSSA Status

Installation

Install-Package SpatialFocus.EntityFrameworkCore.Extensions

Usage

This extension provides two extension methods to modify the modelBuilder in the OnModelCreating method in the DbContext class.

using SpatialFocus.EntityFrameworkCore.Extensions;

public partial class MyContext : DbContext
{
   // ...

   protected override void OnModelCreating(ModelBuilder modelBuilder)
   {
      // Any custom model configuration should come before calling ConfigureEnumLookup and ConfigureNames
      // ...

      modelBuilder.ConfigureEnumLookup(EnumLookupOptions.Default.UseStringAsIdentifier());

      modelBuilder.ConfigureNames(NamingOptions.Default.SkipTableNamingForGenericEntityTypes());

      // Any configuration after calling the two methods will not be processed by this Extension
      // ...
   }
}

Configuration Options

There are two extension methods in the OnModelCreating method in the DbContext class:

Naming Schemes

Naming Source

Examples

For an exemplary usage, see the DemoContext in the sample project.

License

FOSSA Status


Made with :heart: by Spatial Focus