Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute
5.0.1.2
dotnet add package Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute --version 5.0.1.2
NuGet\Install-Package Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute -Version 5.0.1.2
<PackageReference Include="Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute" Version="5.0.1.2" />
paket add Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute --version 5.0.1.2
#r "nuget: Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute, 5.0.1.2"
// Install Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute as a Cake Addin #addin nuget:?package=Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute&version=5.0.1.2 // Install Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute as a Cake Tool #tool nuget:?package=Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute&version=5.0.1.2
DecimalAttribute for EntityFramework Core
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?
- Add
Toolbelt.EntityFrameworkCore.DecimalAttribute
package to your project.
> dotnet add package Toolbelt.EntityFrameworkCore.DecimalAttribute
Supported Versions
The version of EF Core | Version of this package |
---|---|
v.9.0 | v.5.0.1 or later (recommended), v.5.0, v.3.1 |
v.8.0 | v.5.0.1 or later (recommended), v.5.0, v.3.1 |
v.7.0 | v.5.0.1 or later (recommended), v.5.0, v.3.1 |
v.6.0 | v.5.0.1 or later (recommended), v.5.0, v.3.1 |
v.5.0 | v.5.0.1 or later (recommended), v.5.0, v.3.1 |
v.3.1 | v.5.0.1 or later (recommended), v.5.0, v.3.1 |
v.3.0 | v.5.0.1 or later (recommended), v.5.0, v.3.1, v.3.0 |
v.2.0, 2.1, 2.2 | v.1.0.x |
- Annotate your model with
[Decimal(precision, scale)]
attribute that lives inToolbelt.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; }
}
- [Important] Override
OnModelCreating()
method of your DbContext class, and callBuildDecimalColumnTypeFromAnnotations()
extension method which lives inToolbelt.ComponentModel.DataAnnotations
namespace.
using Microsoft.EntityFrameworkCore;
using Toolbelt.ComponentModel.DataAnnotations;
public class MyDbContext : DbContext
{
...
// Override "OnModelCreating", ...
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// .. and invoke "BuildDecimalColumnTypeFromAnnotations"!
modelBuilder.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.
Appendix
Upgrade an existing project
To upgrade an existing project that uses ver.3 or before to use ver.5 or later of this package:
- Please confirm that the version of this package you use is ver.5 or later.
PM> Update-Package Toolbelt.EntityFrameworkCore.DecimalAttribute
- Remove
using Toolbelt.ComponentModel.DataAnnotations.Schema;
, and insertusing 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
- Toolbelt.EntityFrameworkCore.DecimalAttribute - Release Notes
- Toolbelt.EntityFrameworkCore.DecimalAttribute.Attibute - Release Notes
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute:
Package | Downloads |
---|---|
Toolbelt.EntityFrameworkCore.DecimalAttribute
[Decimal(p, s)] attribute and model builder extension for EntityFramework Core. |
GitHub repositories
This package is not used by any popular GitHub repositories.
v.5.0.1.2
- Supports EntityFramework Core 9.0
- Update README.md