Copied to clipboard

Flag this post as spam?

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

  • andrew shearer 493 posts 616 karma points
    Nov 04, 2020 @ 03:57
    andrew shearer

    built in UmbracoMapper: ability to "auto map"?


    I’m looking into the UmbracoMapper (not to be confused with the UmbracoMapper package by Andy Butland of the same name) and wondered if it does any property automapping by convention? It seems that you have to “DefineMaps” for everything?

    The docs say “works in ways very similar to AutoMapper” but I can’t get to automatically map properties between source and target of the same name/type.

    Does it actually automap?

    Thanks Andrew

    (using umbraco 8.9)

  • andrew shearer 493 posts 616 karma points
    Nov 04, 2020 @ 20:09
    andrew shearer

    actually, maybe this explains what im asking: (from further down the page

    The analyzer verifies that every publicly settable property of target is assigned a value. If a property is not assigned a value, the tool raises a build error (ie. the code will not compile).

    Since, contrary to AutoMapper, mapping is not implicit nor automatic, this ensures that, should a new property be added to ISource, an error would be raised until the corresponding mappings are updated.

    I probably don't understand the advantage/purpose of a mapper that requires you to be explicit about every property mapping. I could write that code without umbracomapper?

    some insight would be appreciated :)

  • Harry Spyrou 212 posts 604 karma points
    Jul 20, 2022 @ 09:44
    Harry Spyrou

    Did you find how to map automatically? I'm running into the same exact thing. Which basically does not help. If I'm to fully map my source models to view models, I could be doing it manually in my controllers.

  • andrew shearer 493 posts 616 karma points
    Jul 20, 2022 @ 21:02
    andrew shearer

    hi Harry - sorry no i didn't find a way to make the umbraco mapper "auto map" but i haven't really revisited this since my post (im trying to remember what i wouldve done, probably just assigned properties manually)

  • Tim 64 posts 87 karma points
    Nov 11, 2022 @ 16:27

    I'm going to bump this question, as I have the same issue.

    I want to map an iPublishedContent to a custom model, automatically so items with the same name are mapped. But I don't want to have to define a map for every single time I use the mapper.

Please Sign in or register to post replies

Write your reply to: