如何在 WCF RIA 领域服务类中使用 EFv5 的 dbGeography 空间数据类型

3
我正在使用 EFv5,其中包含地理数据类型。因此我有一个名为 Place 的实体,它具有一个名为 geoLocation 的属性,类型为 geography。VS 2012 自动为该实体创建了代码,且该 geography 类型的属性类型已声明为 System.Data.Spatial.DbGeography。所以一切都很好。
但是当我添加域服务类并勾选要包括我的 place 实体时,解决方案停止编译,因为 domainservice.metaData.cs 文件似乎无法为地理类型创建属性,并出现“Entity 'SilverlightApplication1.Web.Place' has a property 'GeoLocation' with an unsupported type”错误消息。
那么我该如何在域服务类中包括这个地理数据类型呢?
我尝试手动将属性添加到已创建的元数据文件中,但仍然收到相同的错误消息。
1个回答

3

我在MVC项目中的领域类中使用DbGeography类型获得了成功。

我定义我的领域类如下。

using System.Data.Spatial;

namespace MyApp.DomainClasses
{
    public class Address
    {
        public int Id { get; set; }
        public string StreetAddress { get; set; }
        public string InternalMailCode { get; set; }
        public string City { get; set; }
        public string Country { get; set; }
        public string PostalCode { get; set; }
        public string StateProvince { get; set; }
        public DbGeography Location { get; set; }

    }
} 

然后我可以使用类似这样的查询。
var myLocation = DbGeography.FromText(gpsLocation);

var addresses= (from a in context.Addresses
               orderby a.Location.Distance(myLocation)
               select a).Take(10);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接