-
Notifications
You must be signed in to change notification settings - Fork 6
Object Types (Nested models)
Consider the following scenario: let's say we have a HomePage doc type (and associated template) that, among other things, allows the content editor to select a featured blog post using a simple Content Picker. Let's say the content picker has the alias featuredBlogEntry
.
Here's how we might want our view model to look:
[UmbracoEntity(AutoMap = true)]
public class HomePageViewModel
{
public string Title { get; set; }
public string SidebarCopy { get; set; }
public BlogEntryViewModel FeaturedBlogEntry { get; set; }
}
In this case, Vault will create the HomePageViewModel instance as you would expect, fully hydrating both the HomePageViewModel
basic properties as well as all the properties in the FeaturedBlogEntry
property.
For a deeper understanding of how Vault determines how to hydrate properties, including nested types, see the section on Type Handlers below.
A word of caution: Vault currently has no depth limits for hydrating object graphs. This comes up less often with view models, but keep in mind that deep graphs or recursion could cause performance problems and/or infinite loops. Future versions of Vault may include limits and opt-outs for such situations.