Я новичок в использовании ViewModels, и мне интересно, приемлемо ли для ViewModel включать экземпляры моделей домена в качестве свойств, или должны ли свойства этих моделей домена быть свойствами самого ViewModel? Например, если у меня есть класс Album.cs
public class Album
{
public int AlbumId { get; set; }
public string Title { get; set; }
public string Price { get; set; }
public virtual Genre Genre { get; set; }
public virtual Artist Artist { get; set; }
}
Как правило, у ViewModel есть экземпляр класса Album.cs
, или у вас есть свойства ViewModel для каждого из свойств класса Album.cs
.
public class AlbumViewModel
{
public Album Album { get; set; }
public IEnumerable<SelectListItem> Genres { get; set; }
public IEnumerable<SelectListItem> Artists { get; set; }
public int Rating { get; set; }
// other properties specific to the View
}
public class AlbumViewModel
{
public int AlbumId { get; set; }
public string Title { get; set; }
public string Price { get; set; }
public IEnumerable<SelectListItem> Genres { get; set; }
public IEnumerable<SelectListItem> Artists { get; set; }
public int Rating { get; set; }
// other properties specific to the View
}