![]() |
VOOZH | about |
dotnet add package Enigmatry.Entry.SmartEnums.EntityFramework --version 10.2.3
NuGet\Install-Package Enigmatry.Entry.SmartEnums.EntityFramework -Version 10.2.3
<PackageReference Include="Enigmatry.Entry.SmartEnums.EntityFramework" Version="10.2.3" />
<PackageVersion Include="Enigmatry.Entry.SmartEnums.EntityFramework" Version="10.2.3" />Directory.Packages.props
<PackageReference Include="Enigmatry.Entry.SmartEnums.EntityFramework" />Project file
paket add Enigmatry.Entry.SmartEnums.EntityFramework --version 10.2.3
#r "nuget: Enigmatry.Entry.SmartEnums.EntityFramework, 10.2.3"
#:package Enigmatry.Entry.SmartEnums.EntityFramework@10.2.3
#addin nuget:?package=Enigmatry.Entry.SmartEnums.EntityFramework&version=10.2.3Install as a Cake Addin
#tool nuget:?package=Enigmatry.Entry.SmartEnums.EntityFramework&version=10.2.3Install as a Cake Tool
This library provides integration between Smart Enums and Entity Framework Core, enabling you to use Smart Enum types as properties in your entity models.
Use this library to seamlessly store and retrieve Smart Enum values when using Entity Framework Core as your ORM.
Add the package to your project:
dotnet add package Enigmatry.Entry.SmartEnums.EntityFramework
Configure your DbContext to use Smart Enum converters:
using Ardalis.SmartEnum;
using Enigmatry.Entry.SmartEnums.Entities;
using Enigmatry.Entry.SmartEnums.EntityFramework;
using Microsoft.EntityFrameworkCore;
// Example SmartEnum
public class ProductCategory : SmartEnum<ProductCategory>
{
public static readonly ProductCategory Electronics = new(1, nameof(Electronics));
public static readonly ProductCategory Clothing = new(2, nameof(Clothing));
public static readonly ProductCategory Books = new(3, nameof(Books));
public static readonly ProductCategory HomeGoods = new(4, nameof(HomeGoods));
private ProductCategory(int id, string name) : base(id, name) { }
}
// Entity with SmartEnum property
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public ProductCategory Category { get; set; }
}
// Entity that uses SmartEnum as primary key
public class CategoryInfo : EntityWithEnumId<ProductCategory>
{
public string Description { get; set; }
}
// Configuration for the CategoryInfo entity
public class CategoryInfoConfiguration : EntityWithEnumIdConfiguration<CategoryInfo, ProductCategory>
{
public CategoryInfoConfiguration() : base(nameMaxLength: 50) { }
}
public class ApplicationDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
public DbSet<CategoryInfo> CategoryInfos { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Configure all SmartEnums in the application
modelBuilder.EntryConfigureSmartEnums();
// Option 1: Configure a specific SmartEnum property
modelBuilder.Entity<Product>()
.Property(p => p.Category)
.HasSmartEnumConversion();
// Option 2: Apply the entity configuration
modelBuilder.ApplyConfiguration(new CategoryInfoConfiguration());
}
}
Using the newly configured model:
// Create and save an entity with a SmartEnum property
using (var context = new ApplicationDbContext())
{
var product = new Product
{
Name = "Laptop",
Category = ProductCategory.Electronics
};
context.Products.Add(product);
await context.SaveChangesAsync();
}
// Query entities by SmartEnum value
using (var context = new ApplicationDbContext())
{
var electronicsProducts = await context.Products
.Where(p => p.Category == ProductCategory.Electronics)
.ToListAsync();
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.2.3 | 102 | 6/1/2026 |
| 10.2.3-preview.4 | 59 | 6/1/2026 |
| 10.2.2 | 223 | 4/27/2026 |
| 10.2.1-preview.1 | 58 | 4/27/2026 |
| 10.1.0 | 221 | 4/16/2026 |
| 10.0.1 | 97 | 5/19/2026 |
| 10.0.1-preview.2 | 72 | 4/16/2026 |
| 10.0.0 | 115 | 4/2/2026 |
| 9.6.0 | 116 | 3/18/2026 |
| 9.5.0 | 215 | 1/26/2026 |
| 9.4.0 | 375 | 12/22/2025 |
| 9.3.1-preview.3 | 264 | 12/18/2025 |
| 9.3.1-preview.1 | 178 | 11/25/2025 |
| 9.3.0 | 848 | 11/10/2025 |
| 9.2.0 | 227 | 9/24/2025 |
| 9.1.1-preview.5 | 229 | 8/8/2025 |
| 9.1.1-preview.4 | 152 | 6/27/2025 |
| 8.3.1-preview.1 | 153 | 12/24/2025 |
| 8.3.0 | 199 | 12/23/2025 |
| 8.2.0 | 222 | 9/24/2025 |