Does ViewModel Increase Web Applications

As far as I understand, using view models can do web developers. life is much simpler, in the sense that we can use this approach to display only the necessary properties in localized strings. I also use mvc3 validation to view jquery etc.

Now I doubt it, since I have a real bottleneck in my webapp. requesting all objects (20 of them) like this

 List<Domain.Property> data = session.Query<Domain.Property>().ToList();    
 return PropertyViewModel.FromDomainModel(data);

and this list of property objects is sent to my ViewModel, where FromDomainModel is located, which expects Object List objects like this

List<PropertyViewModel> dataVm = new List<PropertyViewModel>();
{
            foreach (Property p in x)
            {
                dataVm.Add(new PropertyViewModel(p));
            }
            return dataVm;
}

now in the same class i use

public PropertyViewModel(Property x)
        {
            Id = x.Id;
            Created = x.Created;
            Title = x.Title;
             ....
            Photo = x.Photos.First();
}

, viewmodel, viewmodel , , ( ). , .

. .

, , , , .

Update: 20Entities, , , 67 , .

+5
3

, , , . # - , .

, , - .

+3

. , , .

N + 1 , .

+1

You should not notice a bottleneck due to ViewModels, instead it sounds like a performance problem with calls in your database, problem n + 1 is really a general performance problem with ORM, you should check the number of calls to your database. Entity Framework Profiler is a really good debugger for EF, it will show you the number of calls in your database, and if the performance is not very good, it will offer you how to improve it.

0
source

All Articles