问题很简单:
public class UserViewModel {
public string Name {get; set;}
public IEnumerable<BookViewModel> Books {get; set;}
public UserViewModel FromUser(User user) {
this.Name = user.Name;
this.Books = user.Books.select(x => new BookViewModel.FromBook(x)).ToList();
}
}
public class BookViewModel : Entity {
public string Title {get; set;}
public UserViewModel User {get; set;}
public BookViewModel FromBook(Book book) {
this.Title = book.Title;
this.User = UserViewModel.FromUser(book.User);
}
}
解决该问题的最佳方法是什么?当我得到UserViewModel
时,我将去BookViewModel
,然后从那里回到UserViewModel
,wchich给了我stack Exception
。