As far as I can understand using view models can make web dev. life much easier, in sense that we can use this approach for display only needed properties in localized strings. Also I use in mvc3 view models jquery validation, etc.
Right now I'm in doubt since I have expirience real bottleneck in my webapp. with querying all objects (20 of them) like this
List<Domain.Property> data = session.Query<Domain.Property>().ToList();
return PropertyViewModel.FromDomainModel(data);
and that list of Property objects are send to my ViewModel where is FromDomainModel which expects List of Property objects like this
List<PropertyViewModel> dataVm = new List<PropertyViewModel>();
{
foreach (Property p in x)
{
dataVm.Add(new PropertyViewModel(p));
}
return dataVm;
}
now in same class I'm using
public PropertyViewModel(Property x)
{
Id = x.Id;
Created = x.Created;
Title = x.Title;
....
Photo = x.Photos.First();
}
but using this approach sending collection of objects to viewmodel from where same viewmodel is returned with only few properties which I need, strangly (atleast for me) I expirience multiple entity load and duration time drastically increased.
If you need more info. please ask.
Also if you know for better solution please share.
Update: When using domain model I have 20Entities loaded and when using viewmodel described above 67 entities are loaded which dramatically decrease performanse.