WCF Ria Services 如何创建一个客户端已知的定制实体?

发布于 2024-08-19 18:23:02 字数 985 浏览 1 评论 0原文

我构建了我的实体模型。我的业务对象之一(我们称之为 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,也不能返回 Location(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};                
        }
    }

}

如何在客户端项目中了解我的小自定义的 Store 数据类型? 谢谢你!

I constructed my Entity Model. One of my business objects,let's call it Store has a spatial data type. Very quickly I figured out that spatial fields aren't mapped via EF4. However I struggled my way out, by editing the xml declarations defining a query like the following:

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

At this point I decided to customize my Store entity via a partial class like this, just to make the conversion and still keep the SQLGeography data stored, returning just a double[] at client (as I cannot return neither SqlGeography, neither Location (Bing datatype).

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};                
        }
    }

}

How can I make aware the Store data type of my little customization, at client project?
Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡少年 2024-08-26 18:23:02

只需向您的属性添加一个 setter,RIA Services 代码生成器和序列化程序就应该在客户端版本的 Store 类上创建等效的属性。

希望有帮助...

Just add a setter to your property, and the RIA Services code generator and serializer should create the equivalent property on the client's version of the Store class.

Hope that helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文