ASP.Net MVC Where do you convert from Entities to ViewModels?
Posted
by Pino
on Stack Overflow
See other posts from Stack Overflow
or by Pino
Published on 2010-06-09T09:42:07Z
Indexed on
2010/06/09
9:52 UTC
Read the original article
Hit count: 406
Title pretty much explains it all, its the last thing I'm trying to work into our project. We are structured with a Service Library which contains a function like so.
/// <summary>
/// Returns a single category based on the specified ID.
/// </summary>
public Category GetCategory(int CategoryID)
{
var RetVal = _session.Single<Category>(x => x.ID == CategoryID);
return RetVal;
}
Now Category is a Entity (We are using Entity Framework) we need to convert that to a CategoryViewModel.
Now, how would people structure this? Would you make sure the service function returned a CategoryViewModel? Have the controller pull the data from the service then call another function to covnert to a view model?
© Stack Overflow or respective owner