The problem that the decimal type of linq is saved to the database is saved to only two digits after the decimal point, linqdecimal
The problem of saving a decimal type to data today has plagued me for a long time, finally, a small setup problem is solved ····
If you don't talk much about it, just ask the question and say the answer:
Problem: when using EF DbContext To Save decimal type data to the database, by default, only the first two decimal places are saved, and the remaining decimal places are set to 0;
For example, if 1.23456789 is saved, the actual data saved to the database is 1.23000000;
It's just a pitfall. If it's accurate to multiple digits after the decimal point, you can only give it to two of you. This is definitely not enough for me. What else can be set as powerful as linq, this problem is solved as follows:
Solution: when creating a DbContext, override the DbContext. OnModelCreating () method, and then specify the accuracy using the following method:
Protected override void OnModelCreating (DbModelBuilder modelBuilder) {// solve the problem of saving decimal data to the database in DbContext. By default, only the first two decimal places after the decimal point are saved, and the remaining places are set to 0, in this way, the modelBuilder with the decimal point is saved. entity <Models_VideoDeviceInfo> (). property (p => p. longitudeX ). hasPrecision (18, 7); modelBuilder. entity <Models_VideoDeviceInfo> (). property (p => p. latitudeY ). hasPrecision (18, 7); modelBuilder. entity <Models_VideoResource> (). property (p => p. latitude ). hasPrecision (18, 7); modelBuilder. entity <Models_VideoResource> (). property (p => p. longpolling ). hasPrecision (18, 7 );}
It's just that simple. It takes me half a day to complete my work ······