开发者

RIA: how to get functionality, not a data

On the server side I have the following class:

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

The problem is that each field is calculated and transferred to the client (to the Silvelight application), for example 'FullName' property:

    [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开发者_StackOverflow中文版.RaisePropertyChanged("FullName");
                this.OnFullNameChanged();
            }
        }
    }

Instead of data transferring (that is traffic consuming, in some cases it introduces significant overhead). I would like to have a calculation on the client side (silverlight aplpication).

Is this possible without manual duplication of the property implementation?

Thank you.


Move the calculated properties to a different file as a partial class and utilize teh "Shared" naming convetion (MyFileName.Shared.cs). Example:

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

The code in the Shared file will show up on the client side.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜