如何,WCF Ria Services可以在客户端创建一个自定义实体?

时间:2010-02-01 22:25:54

标签: silverlight entity-framework wcf-ria-services geospatial

我构建了我的实体模型。我的业务对象之一,我们称之为Store具有空间数据类型。很快我发现空间字段不是通过EF4映射的。但是我通过编辑定义如下查询的xml声明来解决问题:

  <EntitySet Name="Stores" EntityType="Eltrun.OnShelfAuditModel.Store.Stores">
    <DefiningQuery>
      SELECT [rowId], [storeName], [location].STAsText() as location FROM Stores
    </DefiningQuery>
  </EntitySet>

此时我决定通过像这样的部分类来自定义我的Store实体,只是为了进行转换并仍然保存SQLGeography数据,在客户端返回一个double [](因为我既不能返回SqlGeography,也不能位置(Bing数据类型)。

public partial class Store
{
    public double[] StoreLocation
    {
        get
        {
            SqlGeography geoLocation = SqlGeography.
                 STPointFromText(new SqlChars(this.location.ToCharArray()), 4326);
            return new double[]{
                           (double)geoLocation.Lat, 
                           (double)geoLocation.Long};                
        }
    }

}

如何在客户端项目中了解我的小定制的商店数据类型? 谢谢!

1 个答案:

答案 0 :(得分:1)

只需在您的属性中添加一个setter,RIA Services代码生成器和序列化器就应该在Client类的Store类上创建等效属性。

希望有帮助...