views:

243

answers:

2

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 any possible conversion between the DTO and the Vview model properties.

+1  A: 

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.

HTH,
Kent

Kent Boogaart
That is pretty much what I thought I would have to do. It just seems a bit painful that I have to map domain objects to DTOs then DTOs to View Models. Is there any way to make the mapping easier that you know of?
Burt
AutoMapper, Emit Mapper etc.
arconaut
+1  A: 

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/

bobble79