When you preserve decimal type data by System.Data.Entity.DbContext, only the decimal place 2 bits is reserved by default. To solve this problem, you can add the appropriate code in the Onmodelcreating event, and refer to the following code for the shop. The longitude is set to 20 bits of decimal place:
public class userdbcontext:system.data.entity.dbcontext{public Userdbcontext () : Base ("Mycontext") { This . configuration.proxycreationenabled = false; This. configuration.lazyloadingenabled = false; } protected override void Onmodelcreating (Dbmodelbuilder modelBuilder) { modelbuilder.entity<shop> (). (Shop = shop. Longitude). Hasprecision (+); Modelbuilder.entity<shop> (). (Shop = shop. Latitude). Hasprecision (+); Modelbuilder.entity<user> (). Property (user = user. Artificerlatitude). Hasprecision (+); Modelbuilder.entity<user> (). Property (user = user. Artificerlongitude). Hasprecision (+); } Public dbset<user> Users {get; set;} Public dbset<shop> Shops {get; set;}}
Fix always keep decimal 2-bit problem when using DbContext to save data