. Net Entity Framework Core configures floating-point precision with Hascolumntype

Source: Internet
Author: User

First, preface

The previous time with the. NET Entity Framework core Framework, you need to configure the precision of floating-point numbers, and found that the. NET Entity Framework core does not have a hasprecision method. Find less information on the web, and finally, with official documentation, try using Hascolumntype to configure floating-point accuracy successfully.

Ii. Hascolumntype Official Document description

Document Connection:

https://docs.microsoft.com/zh-cn/dotnet/api/ Microsoft.entityframeworkcore.relationalpropertybuilderextensions.hascolumntype?view=efcore-2.0#microsoft_ Entityframeworkcore_relationalpropertybuilderextensions_hascolumntype_microsoft_entityframeworkcore_metadata_ Builders_propertybuilder_system_string_

Iii. comparing the. NET Entity Framework and the. NET Entity Framework Core Configuration

. Net Entity Framework Methods:

 Public classmyprojectcontext:dbcontext{ PublicDbset<order> Orders {Get;Set; } protected Override voidonmodelcreating (Dbmodelbuilder modelBuilder) {Base. Onmodelcreating (ModelBuilder);
//to configure the amount of an order floating point precision is decimal (18,6)modelbuilder.entity<Order> (). Property (t = t.amount). Hasprecision ( -,6); } }

The. Net Entity Framework Core method:

 Public classmyprojectcontext:dbcontext{ PublicDbset<order> Orders {Get;Set; } protected Override voidonmodelcreating (Dbmodelbuilder modelBuilder) {Base.            Onmodelcreating (ModelBuilder); Modelbuilder.entity<Order> (b ={//to configure the amount of an order floating point precision is decimal (18,6)B.property (P= P.amount). Hascolumntype ("decimal (18,6)");        }); }   }

. Net Entity Framework Core configures floating-point precision with Hascolumntype

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.