I have the following DTO definition:-
[DataContract]
public class AddProductDTO
{
[DataMember]
public string Code { get; set; }
[DataMember]
public List<string> Categories { get; set; }
}
and a viewmodel that currently has a constructor as follows :-
public AddProdctViewModel()
{
Model = new AddProductDTO();
}
the AddProductDTO has been added as a service reference directly in VisualStudio 2010
In my view I have an (Xceed) WPF datagrid in which I would like to be able to enter categories directly. Currently its itemssource is set to Model.Categories. However, this is not working as the Model.Categories value is null.
This raises a few questions I hope I get can some assistance on
- In MVVM is it OK to directly reference the WCF DTO class as the model or should I wrap this in something else?
- Why is the Model.Categories coming out as null when AddProductDTO is created?*
- What is the recommended way of using WPF/WCF/MVVM to populate a list that is part of the DTO?
Personally I prefer to use
Modelclasses for my data objects, and something like AutoMapper to map DTOs to Models. This allows me to keep things like validation (IDataErrorInfo) and property change notifiers (INotifyPropertyChanged) on the Model object, without having to include that data when going to/from WCFAs for
Model.Categoriesbeingnull, usually I’ll set list objects to a blank list the first time thegetmethod of the property is called to avoid this sort of problem.