我试图使用c#,实体框架 – @R_301_457@优先和mvc来编写/读取ms sql@R_301_457@的纬度和经度.
问题是lat / long只显示2位小数,即使它们在@R_301_457@中是正确的.@R_301_457@的字段为数字(18,6).
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder) { modelBuilder.Entity<STORE_LOCATION>().Property(location => location.LATITUDE).HasPrecision(18,6); modelBuilder.Entity<STORE_LOCATION>().Property(location => location.LONGITUDE).HasPrecision(18,6); }
2个问题 – 我是否应该修改上下文文件中的OnModelCreating – 即使它警告更改可能会在重新生成时丢失,如何保持代码不会舍入小数?
任何帮助赞赏!
解决方法
Should I be modifying the OnModelCreating in the context file – even though it warns changes may be lost on regeneration and how do I keep the code from rounding the decimals?
否 – 在另一个文件中实现上下文的部分类,并在那里实现OnModelCreating
至于精度 – 您是否检查过调试器中对象的值与页面上显示的值?在渲染期间可能发生舍入.
[DisplayFormat(DataFormatString = "{0:0.0#####}",ApplyFormatInEditMode = true)]