Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVVM with Collections

Tags:

c#

mvvm

If i have a model that should contain an collection e.g. book -> authors

how sould i do it

like:

public class Book
{
    public string Title { get; set; }
    public List<Author> Authors { get; set; }
}

or more like:

public class Book
{
    public string Title { get; set; }
    public List<AuthorViewModel> Authors { get; set; }
}

which of this both is the more common way to do this and how do i get the view out of the ViewModel?

like image 946
Karl_Schuhmann Avatar asked Jan 28 '26 01:01

Karl_Schuhmann


1 Answers

This one is definitely wrong:

public class Book
{
    public string Title { get; set; }
    public List<AuthorViewModel> Authors { get; set; }
}

But this would be OK:

public class BookViewModel
{
    public string Title { get; set; }
    public List<AuthorViewModel> AuthorModels { get; set; }
}
like image 96
Henk Holterman Avatar answered Jan 30 '26 15:01

Henk Holterman