Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ian Dawson 20 posts 80 karma points
    Jan 17, 2015 @ 16:53
    Ian Dawson
    0

    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

  • Andy Butland 362 posts 1954 karma points MVP 4x c-trib
    Jan 18, 2015 @ 09:43
    Andy Butland
    0

    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:

           [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,

    }, 
    });

    Cheers

    Andy

  • Ian Dawson 20 posts 80 karma points
    Jan 19, 2015 @ 14:08
    Ian Dawson
    0

    Hi Andy, thanks for this. Works great. Ian

Please Sign in or register to post replies

Write your reply to:

Draft