解决使用DbContext保存Decimal数据时总是保留小数位2位问题
2015-05-06 11:16
253 查看
通过System.Data.Entity.DbContext保留Decimal类型数据时,默认只保留小数位2位。要解决该问题,可以通过在OnModelCreating事件中添加相应代码即可,具体参考如下代码中将shop.Longitude设置为小数位20位:
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>().Property(shop => shop.Longitude).HasPrecision(30, 20);
modelBuilder.Entity<Shop>().Property(shop => shop.Latitude).HasPrecision(30, 20);
modelBuilder.Entity<User>().Property(user => user.ArtificerLatitude).HasPrecision(30, 20);
modelBuilder.Entity<User>().Property(user => user.ArtificerLongitude).HasPrecision(30, 20);
}
public DbSet<User> Users { get; set; }
public DbSet<Shop> Shops { get; set; }
}
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>().Property(shop => shop.Longitude).HasPrecision(30, 20);
modelBuilder.Entity<Shop>().Property(shop => shop.Latitude).HasPrecision(30, 20);
modelBuilder.Entity<User>().Property(user => user.ArtificerLatitude).HasPrecision(30, 20);
modelBuilder.Entity<User>().Property(user => user.ArtificerLongitude).HasPrecision(30, 20);
}
public DbSet<User> Users { get; set; }
public DbSet<Shop> Shops { get; set; }
}
相关文章推荐
- 使用MySQL保存中文数据时,经常会遇到乱码问题的解决思路
- 问题解决——在结构体中使用set保存结构体数据
- 问题解决——在结构体中使用set保存结构体数据
- java使用POI解析Excel表格中由纯数字组成的字符串报错问题&解决数据自动保存为科学计数法问题
- ListView中使用EditText(解决EditText焦点丢失、保存数据以及滚动冲突的问题)
- Oracle数据使用中出现的几种问题及解决方法
- 解决AngularJS在IE下取数据总是缓存的问题
- 解决VS2013使用MySQL无法创建ADO.NET实体数据类型的问题
- C++编程笔记:使用WinHTTP实现HTTP访问(解决接收UTF8数据乱码问题)
- XUtils框架中HttpUtils使用Get请求时总是返回相同信息的问题解决
- echarts2.0 时间轴搭配力导向图使用+时间轴数据覆盖问题的解决
- ListView分页功能(3) 解决使用footerView数据不足,显示问题
- 使用SQLServer同义词和SQL邮件,解决发布订阅中订阅库丢失数据的问题
- iOS开发中使用FMDB解决数据存储问题
- iOS开发中使用FMDB解决数据存储问题
- AngularJS在IE下取数据总是缓存问题的解决方法
- 解决下载下来的flexgrid.js下载下来直接使用数据不能显示的问题
- win7下使用共享内存方式CreateFileMapping返回GetLastError总是0x5的问题解决
- 使用@noescape解决Swift闭包“保留环”问题
- Android网络编程之使用get方式向服务端提交数据和乱码问题的解决