. Net Entity Framework Core uses HasColumnType to configure the floating point precision,

Source: Internet
Author: User

. Net Entity Framework Core uses HasColumnType to configure the floating point precision,

I. Preface

Some time ago, we used. Net Entity Framework core to build a Framework. We needed to configure the floating point precision. We found that. Net Entity Framework core does not have the HasPrecision method. There are few materials available on the Internet. Finally, the official documentation explains how to use HasColumnType to configure the floating point precision.

 

Ii. HasColumnType official documentation

Document connection:

Https://docs.microsoft.com/zh-cn/dotnet/api/microsoft.entityframeworkcore.relationalpropertybuilderextensions.hascolumntype? View = efcore-2.0 # Empty _

 

 

Iii. Comparison of. Net Entity Framework and. Net Entity Framework Core Configuration


 . Net Entity Framework method:

Public class MyProjectContext : DbContext
{
         Public DbSet<Order> Orders { get; set; }

         Protected override void OnModelCreating(DbModelBuilder modelBuilder)
         {
             base.OnModelCreating(modelBuilder);

             / / Configure the amount of the order floating point precision is decimal (18,6)
             modelBuilder.Entity<Order>().Property(t => t.Amount).HasPrecision(18, 6);
}
} 



.Net Entity Framework Core method:

 


Public class MyProjectContext : DbContext
{
         Public DbSet<Order> Orders { get; set; }

         Protected override void OnModelCreating(DbModelBuilder modelBuilder)
         {
             base.OnModelCreating(modelBuilder);
             modelBuilder.Entity<Order>(b =>
             {
/ / Configure the amount of the order floating point precision is decimal (18,6)
                 b.Property(p => p.Amount).HasColumnType("decimal(18,6)");
             });
}
} 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.