Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute 1.0.0

[Decimal(p, s)] attribute for EntityFramework Core.

There is a newer version of this package available.
See the version list below for details.
Install-Package Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute -Version 1.0.0
dotnet add package Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute --version 1.0.0
<PackageReference Include="Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute, 1.0.0"
#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.Attribute as a Cake Addin
#addin nuget:?package=Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute&version=1.0.0

// Install Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute as a Cake Tool
#tool nuget:?package=Toolbelt.EntityFrameworkCore.DecimalAttribute.Attribute&version=1.0.0
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
  1. Annotate your model with [Decimal(precision, scale)] attribute that lives in Toolbelt.ComponentModel.DataAnnotations.Schema namespace.
using Toolbelt.ComponentModel.DataAnnotations.Schema;

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)
    {
        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

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.

License

MIT License

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
  1. Annotate your model with [Decimal(precision, scale)] attribute that lives in Toolbelt.ComponentModel.DataAnnotations.Schema namespace.
using Toolbelt.ComponentModel.DataAnnotations.Schema;

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)
    {
        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

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.

License

MIT License

Release Notes

v.1.0.0
- 1st release.

  • .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.

Version History

Version Downloads Last updated
5.0.0 794 8/14/2020
1.0.0 733 2/21/2019