Skip to content

Instantly share code, notes, and snippets.

@lbargaoanu
Created March 25, 2018 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbargaoanu/27b0d600e11d3da5d93eeb112949d67a to your computer and use it in GitHub Desktop.
Save lbargaoanu/27b0d600e11d3da5d93eeb112949d67a to your computer and use it in GitHub Desktop.
public static void Main()
{
Mapper.Initialize(cfg=>
{
});
Mapper.AssertConfigurationIsValid();
var book = new Book
{
Name = "B1",
};
book.Authors = new List<Author>{new Author{Name="A1",Books=new List<Book>{book}},new Author{Name="A2",Books=new List<Book>{book}}};
var bookM = Mapper.Map<BookViewModel>(book).Dump();
}
public class Book
{
public string Name { get; set; }
public List<Author> Authors { get; set; }
}
public class Author
{
public string Name { get; set; }
public List<Book> Books { get; set; }
}
public class BookViewModel
{
public string Name { get; set; }
public List<AuthorViewModel> Authors { get; set; }
}
public class AuthorViewModel
{
public string Name { get; set; }
public List<BookViewModel> Books { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment