WCF Ria Services 如何创建一个客户端已知的定制实体?
我构建了我的实体模型。我的业务对象之一(我们称之为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需向您的属性添加一个 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...