开发者

MVVM View Model DTOs

I have a WCF based application that uses the services to access repositories on the server side. I am passing DTOs from the server to the client and was wondering how best to make the DTOs part pf the view model.

I have a workign example of just plain properties on the view model but was unsure how to deal with actual DTO objects and a开发者_如何学运维ny possible conversion between the DTO and the Vview model properties.


Your question is very general, but the pattern usually looks something like this:

public class CustomerViewModel : ViewModel
{
    private readonly CustomerDTO _customer;

    ...

    public string Name
    {
        get { return _customer.Name; }
        set
        {
            if (_customer.Name != value)
            {
                _customer.Name = value;
                OnPropertyChanged(() => this.Name);
            }
        }
    }
}

You'll need to ask a more specific question if this doesn't make any sense.


I'm actually developing a library for mapping your dtos to your view models and your view models to your view. You can check it out at http://fluentviewmodel.codeplex.com/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜