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 512 posts 661 karma points
    Nov 04, 2020 @ 03:57
    andrew shearer
    1

    built in UmbracoMapper: ability to "auto map"?

    Hello

    I’m looking into the UmbracoMapper https://our.umbraco.com/documentation/Reference/Mapping/ (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 512 posts 661 karma points
    Nov 04, 2020 @ 20:09
    andrew shearer
    1

    actually, maybe this explains what im asking: (from further down the page https://our.umbraco.com/documentation/Reference/Mapping/)

    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
    0

    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 512 posts 661 karma points
    Jul 20, 2022 @ 21:02
    andrew shearer
    0

    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 67 posts 90 karma points
    Nov 11, 2022 @ 16:27
    Tim
    0

    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.

  • fatmazayed 41 posts 122 karma points
    Oct 10, 2023 @ 05:51
    fatmazayed
    0

    me too i want to mapp the whole class properities instead of one by one

Please Sign in or register to post replies

Write your reply to:

Draft