Can someone explain how the PropertySets work in UmbracoMapper and the difference between them.
I'm assuming it's so you can specify to map only a certain set of properties. Though I can't find any examples.
Specifically I have a certain case where I only want to map a few of the models properties. Which I guess would require using PropertySet.Custom. But how do I specify the properties to map?
e.g. in this line of code here, where do I specify the properties to map??
The propertySet parameter doesn't actually do what you are looking for I'm afraid. It's intended as a simple flag to allow to you map just all native properties of IPublishedContent (Id, Name etc.) OR just all custom properties (all the ones put on document types). The default is to map both. To be honest, can't quite remember the use case for this, but a colleague needed it at some point so we added it.
Your post though prompted me to think we don't have a simple Ignore property to use, if you want to exclude a property from mapping when it otherwise would be. So I've added this in the version 1.4.13 - up now on NuGet, GitHub and our.umbraco.org.
If you are using the newer attributes you can just add:
[PropertyMapping(Ignore = true)] public string MyProperty { get; set; }
Or if you are passing the property mapping dictionary you can do this:
Mapper.Map(CurrentPage, model, new Dictionary<string, PropertyMapping> { "MyProperty", new PropertyMapping { Ignore = true, } }, });
PropertySets
Hi,
Can someone explain how the PropertySets work in UmbracoMapper and the difference between them.
I'm assuming it's so you can specify to map only a certain set of properties. Though I can't find any examples.
Specifically I have a certain case where I only want to map a few of the models properties. Which I guess would require using PropertySet.Custom. But how do I specify the properties to map?
e.g. in this line of code here, where do I specify the properties to map??
Mapper.MapCollection(CurrentPage.GetPropertyValue<>
Thanks, Ian
Hi Ian
The propertySet parameter doesn't actually do what you are looking for I'm afraid. It's intended as a simple flag to allow to you map just all native properties of IPublishedContent (Id, Name etc.) OR just all custom properties (all the ones put on document types). The default is to map both. To be honest, can't quite remember the use case for this, but a colleague needed it at some point so we added it.
Your post though prompted me to think we don't have a simple Ignore property to use, if you want to exclude a property from mapping when it otherwise would be. So I've added this in the version 1.4.13 - up now on NuGet, GitHub and our.umbraco.org.
If you are using the newer attributes you can just add:
Or if you are passing the property mapping dictionary you can do this:
Cheers
Andy
Hi Andy, thanks for this. Works great. Ian
is working on a reply...