Hi - camel cased aliases are the Umbraco default (what gets generated for you if you don't change it), so the convention is that Umbraco Mapper will try to match on camel case.
You can override it using an attribute on a given field like this:
I forgot to mention, that I map descendant (DocTypeAlias), not a property.
public class HomePageViewModel : MasterViewModel
{
public HomePageViewModel()
{
NewsItem = new List<NewsItemViewModel>();
}
public IList<NewsItemViewModel> NewsItem { get; set; }
}
Umbraco names propertyName with small letter first, but DocTypeAlias with Capital letter.
And the second problem is that I have to use name NewsItem or UM wont map.
Adding:
[PropertyMapping(SourceProperty = "Article")]
public IList<ArticleViewModel> Articles { get; set; }
does not help. Still propertyName is with small letter.
If I'm following correctly then you are looking to map the children of your home page to your collection of NewsItems.
In that case you will need a second mapping call - there's nothing (at least at the moment) for "auto-mapping" children of a node (main reason being would be concerned about performance if there were a lot of children/descendants, and so think it's probably better that the developer makes an explicit call to map these).
So think you want something like:
var vm = new HomePageViewModel();
mapper.Map(CurrentPage, vm)
.MapCollection(CurrentPage.Children, vm.NewsItems);
OK - I wonder if you are trying to do something too generic here. It might work but can't say it's a little off the beaten track of what I have tried.
The signature of the custom mapper requires the propertyName (the alias of the content field, which isn't the same thing as the document type alias of the descendent items you are looking for).
If in your application though you have the convention that these will match, you could probably just have some code in your custom mapping function to convert the propertyName into Pascal case (i.e. upper case the first letter).
Custom mapping, propertyName first letter small
Hi,
How to stop Umbraco mapper from making propertyAlias first letter small? If I define propertyAlias with capital letter it is ignored.
Hi - camel cased aliases are the Umbraco default (what gets generated for you if you don't change it), so the convention is that Umbraco Mapper will try to match on camel case.
You can override it using an attribute on a given field like this:
Hi Andy,
Thank you for quick response.
I forgot to mention, that I map descendant (DocTypeAlias), not a property.
Umbraco names propertyName with small letter first, but DocTypeAlias with Capital letter. And the second problem is that I have to use name NewsItem or UM wont map.
Adding:
does not help. Still propertyName is with small letter.
If I'm following correctly then you are looking to map the children of your home page to your collection of NewsItems.
In that case you will need a second mapping call - there's nothing (at least at the moment) for "auto-mapping" children of a node (main reason being would be concerned about performance if there were a lot of children/descendants, and so think it's probably better that the developer makes an explicit call to map these).
So think you want something like:
That is not mapping Children, but Descendants.
In some magic way UM knows that I want to map Article (docTypeAlias)
but... makes first letter small. Umbraco uses capital letter for docTypeAlias.
OK - I wonder if you are trying to do something too generic here. It might work but can't say it's a little off the beaten track of what I have tried.
The signature of the custom mapper requires the propertyName (the alias of the content field, which isn't the same thing as the document type alias of the descendent items you are looking for).
If in your application though you have the convention that these will match, you could probably just have some code in your custom mapping function to convert the propertyName into Pascal case (i.e. upper case the first letter).
is working on a reply...