2010-03-28 50 views
1

在服务器端,我有下面的类:RIA:如何获得的功能,而不是一个数据

public class Customer 
{ 
    [Key] 
    public int Id { get; set; } 

    public string FirstName { get; set; } 

    public string SecondName { get; set; } 

    public string FullName { get { return string.Concat(FirstName, " ", SecondName); } } 
} 

的问题是,每场计算,传输到客户端(在Silvelight应用程序),例如'FullName'属性:

[DataMember()] 
    [Editable(false)] 
    [ReadOnly(true)] 
    public string FullName 
    { 
     get 
     { 
      return this._fullName; 
     } 
     set 
     { 
      if ((this._fullName != value)) 
      { 
       this.ValidateProperty("FullName", value); 
       this.OnFullNameChanging(value); 
       this._fullName = value; 
       this.RaisePropertyChanged("FullName"); 
       this.OnFullNameChanged(); 
      } 
     } 
    } 

而不是数据传输(即流量消耗,在某些情况下,它会引入大量开销)。我想在客户端进行计算(silverlight aplpication)。

这可能没有手动重复的财产执行?

谢谢。

+0

假设这是一个Web表单或其他东西,你不能使用AJAX或JavaScript进行验证吗? – 2010-03-28 22:16:55

+0

我很抱歉,...我能做些什么与验证?功能复制的目的是在不传递FullName属性值的情况下,在FirstName =“Alex”和SecondName =“Sereda”的情况下,在客户端计算并显示FullName为“Alex Sereda”。 – Budda 2010-03-29 15:03:07

回答

0

将计算出的属性作为分部类移动到不同的文件,并利用“共享”命名传递(MyFileName.Shared.cs)。例如:

//Employee.cs 
public partial class Employee 
{ 
    [Key] 
    public string EmployeeId { get; set; } 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
} 

//Employee.Shared.cs 
public partial class Employee 
{ 
    public string LastNameFirst 
    { 
     get { return string.Format("{0}, {1}", LastName, FirstName); } 
    } 
} 

共享文件中的代码将显示在客户端。

相关问题