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