【发布时间】:2015-06-16 13:08:09
【问题描述】:
我得到了LoginViewModel,其中包含一些定义用户在世界上的位置的双精度:
public class LoginViewModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public double Accuracy { get; set; }
}
稍后我想将它们作为用户属性存储在数据库中。
我应该将它们存储为三个双精度值还是其他已定义的类型:大概是 ICollection<DbGeography> 或定义我自己的类型的 ICollection Latitude, Longitude, Accuracy?
【问题讨论】:
-
我会使用 DBGeography,因为它内置了一些函数,例如使用简单的语法计算两个 DbGeography 对象(纬度/经度)之间的距离:
someDbGeohgraphy.Distance(someOtherDbGeography).... 但它确实归结为您计划如何使用 lat/long 道具 -
@SteveG 我没有意识到 .Net 有 DBGeography 类型,我会更新我的答案。
标签: c# asp.net-mvc geolocation entity-framework-6 asp.net-mvc-5.2