Toolbelt.EntityFrameworkCore.DecimalAttribute 5.0.1

.NET Standard 2.0
Install-Package Toolbelt.EntityFrameworkCore.DecimalAttribute -Version 5.0.1
dotnet add package Toolbelt.EntityFrameworkCore.DecimalAttribute --version 5.0.1
<PackageReference Include="Toolbelt.EntityFrameworkCore.DecimalAttribute" Version="5.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Toolbelt.EntityFrameworkCore.DecimalAttribute --version 5.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Toolbelt.EntityFrameworkCore.DecimalAttribute, 5.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Toolbelt.EntityFrameworkCore.DecimalAttribute as a Cake Addin
#addin nuget:?package=Toolbelt.EntityFrameworkCore.DecimalAttribute&version=5.0.1

// Install Toolbelt.EntityFrameworkCore.DecimalAttribute as a Cake Tool
#tool nuget:?package=Toolbelt.EntityFrameworkCore.DecimalAttribute&version=5.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

DecimalAttribute for EntityFramework Core

NuGet Package

What's this?

This class library for Entity Framework Core on .NET Core/.NET Framework provides the ability for you to control the precision and scale of decimal column type, by annotating properties of entity types, like this.

[Decimal(10, 5)] // <-- This!
public decimal Height { get; set; }

How to use?

  1. Add Toolbelt.EntityFrameworkCore.DecimalAttribute package to your project.
> dotnet add package Toolbelt.EntityFrameworkCore.DecimalAttribute

Supported Versions

EF Core version This package version
v.6.0 v.5.0.1 (recommended), v.5.0, v.3.1
v.5.0 v.5.0.1 (recommended), v.5.0, v.3.1
v.3.1 v.5.0.1 (recommended), v.5.0, v.3.1
v.3.0 v.5.0.1 (recommended), v.5.0, v.3.1, v.3.0
v.2.0, 2.1, 2.2 v.1.0.x
  1. Annotate your model with [Decimal(precision, scale)] attribute that lives in Toolbelt.ComponentModel.DataAnnotations.Schema.V5 namespace.
using Toolbelt.ComponentModel.DataAnnotations.Schema.V5;

public class Person
    public int Id { get; set; }

    [Decimal(10, 5)] // <- Here!
    public decimal Height { get; set; }
  1. [Important] Override OnModelCreating() method of your DbContext class, and call BuildDecimalColumnTypeFromAnnotations() extension method which lives in Toolbelt.ComponentModel.DataAnnotations namespace.
using Microsoft.EntityFrameworkCore;
using Toolbelt.ComponentModel.DataAnnotations;

public class MyDbContext : DbContext
    // Override "OnModelCreating", ...
    protected override void OnModelCreating(ModelBuilder modelBuilder)

        // .. and invoke "BuildDecimalColumnTypeFromAnnotations"!

That's all!

BuildDecimalColumnTypeFromAnnotations() extension method scans the DbContext with .NET Reflection technology, and detects [Decimal] attributes, then build models related to decimal column type.

After doing that, decimal type columns in the database which created by EF Core, is configured with precisions and scales that are specified by [Decimal] attribute.


Upgrade an existing project

To upgrade an existing project that uses ver.3 or before to use ver.5 or later of this package:

  1. Please confirm that the version of this package you use is ver.5 or later.
PM> Update-Package Toolbelt.EntityFrameworkCore.DecimalAttribute
  1. Remove using Toolbelt.ComponentModel.DataAnnotations.Schema;, and insert using Toolbelt.ComponentModel.DataAnnotations.Schema.V5; instead.
// 👇 Remove this line...
// using Toolbelt.ComponentModel.DataAnnotations.Schema;

// 👇 Insert this line, instead.
using Toolbelt.ComponentModel.DataAnnotations.Schema.V5;

If you want to use only "DecimalAttribute" without any dependencies...

If you want to use only "DecimalAttribute" class without any dependencies, you can use Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute NuGet package.

Release Notes


MIT License

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

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
5.0.1 533 11/11/2021
5.0.1-preview.1.0 111 6/30/2021
5.0.0 4,241 8/14/2020
3.1.0 316 2/5/2020
3.0.0 302 10/10/2019
1.0.1 339 7/26/2019
1.0.0 391 2/21/2019

- Supports EntityFramework Core 6.0