Silverlight 客户端中实体的帮助程序属性,共享代码

发布于 12-21 05:47 字数 853 浏览 7 评论 0原文

我试图弄清楚如何为给定的实体类型创建在 Silverlight 客户端中公开的附加“计算”属性。我的解决方案结构如下(简化):

命名空间“数据访问”,类库,保存我的 EDMX 托管 silverlight 应用程序以及通过 EDMX 投影的域服务的命名空间“Web”Web 应用程序(因此它引用了“数据访问”项目。) 命名空间“SLApp”,Silverlight 应用程序

我的实体之一是 Person(非常简化):

public partial class Person
{
   public string FirstName {get; set;}
   public string LastName {get; set;}
}

我想要一个名为 FullName 的“帮助器”/“计算”属性,它只需将名字和姓氏放在一起。在过去,这很容易;在过去,这很容易。创建我自己的公共分部类 Person 类并添加属性/逻辑,然后我可以将其用作普通属性。但 RIA 域服务似乎没有公开该属性,因此我无法在客户端上使用它。如果 EDMX 在 Web 应用程序中,我可以使用 .Shared.cs 文件并将其包含在 SL 应用程序中(我猜),但我不希望我的 EDMX 在 Web 应用程序中(感觉很脏:))

我使用 MVVM 模式,这样我就可以在 ViewModel 类上创建属性,但似乎我必须多次复制该逻辑(任何我需要 FullName 属性的 ViewModel)。我尝试为 SL 应用程序中的 Person 对象创建一个名为 FullName 的扩展方法,但显然您无法绑定到扩展方法。

我是 Silverlight 新手,这是我的第一个“真正的”应用程序,所以也许我只是错过了一些非常简单的东西......我希望如此。任何帮助都会很棒。

谢谢你!

I'm trying to figure out how to create additional "calculated" properties that are exposed in a Silverlight client for a given Entity type. My solution structure is as follows (Simplified):

Namespace "Data Access", Class Lib, that holds my EDMX
Namespace "Web" Web app that hosts the silverlight application as well as the Domain Service that projects over the EDMX (So it have a reference to the "Data Access" project.)
Namespace "SLApp", the Silverlight App

One of my entities is Person (very simplified):

public partial class Person
{
   public string FirstName {get; set;}
   public string LastName {get; set;}
}

I want to have a "helper"/"calculated" property called FullName that simply puts the first and the last names together. In the past this was easy; create my own public partial class Person class and add the property/logic and then I can just use it as as normal property. But the RIA Domain Service does not seems to expose that property, so I can't use it on the client. If the EDMX was in the Web application I could use the .Shared.cs file and have it included in the SL app (I guess) but I don't want my EDMX in the web app (feels dirty :) )

I'm using the MVVM pattern so I could just create the Property on the ViewModel class, but seems like I'd have to duplicate that logic a number of times (any ViewModel that I need the FullName property on). I tried creating an extension method for the Person Object in the SL App called FullName, but apparently you can't bind to extension methods.

I'm new to Silverlight this is my first "real" application so maybe I'm just missing something very simple... I hope I am. Any help would be great.

Thank you!

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

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

发布评论

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

评论(1

不知所踪2024-12-28 05:47:27

您是否已将 [DataMember] 属性添加到您的计算属性中?

[DataMember]
public string FullName
{
    get { return string.Format("{0} (1)", this.FirstName, this.LastName); }
}

Have you added [DataMember] Attribute to your calculated property?

[DataMember]
public string FullName
{
    get { return string.Format("{0} (1)", this.FirstName, this.LastName); }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文