2010-03-28 51 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); } 
    } 
} 

共享文件中的代碼將顯示在客戶端。

相關問題