EF5, SQL Server, Longitude and Latitude

后端 未结 4 956
误落风尘
误落风尘 2021-02-13 17:57

I found that the best type to store lat and long in SQL Server is decimal (9,6) (ref. What datatype to use when storing latitude and longitude data in SQL databases?) and so I d

4条回答
  •  生来不讨喜
    2021-02-13 18:37

    Apparently this guy had the exact same problem and solved it thus:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity().Property(a => a.Latitude).HasPrecision(18, 9);
        modelBuilder.Entity().Property(a => a.Longitude).HasPrecision(18, 9);
    }
    

    Although you may want to look at using the spatial data types (particularly geography) in SQL Server 2008 and later.

提交回复
热议问题