Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4366 posts 9472 karma points MVP 2x admin c-trib
    Jul 15, 2019 @ 09:02
    Ismail Mayat
    2

    How to register mapper in v8

    I have created a custom mapping as per https://our.umbraco.com/Documentation/Reference/Mapping/

    The class is definition looks like:

     UserGroupProfile: IMapDefinition
    

    I am trying to compose it as per the documentation:

    composition.WithCollectionBuilder() .Add();

    So I have

     composition.WithCollectionBuilder<MapperCollectionBuilder>().Add(typeof(UserGroupProfile));
    

    This gives error:

    System.InvalidOperationException: Cannot register type Our.Umbraco.RedirectsViewer.Mapping.UserGroupProfile as it does not inherit from/implement Umbraco.Core.Persistence.Mappers.BaseMapper.

    I am guessing I am not registering correctly, does anyone have an example of how to register custom mapper?

    Regards

    Ismail

  • Damiaan 434 posts 1279 karma points MVP 2x c-trib
    Jul 15, 2019 @ 09:24
    Damiaan
    0

    Have you tried inheriting from BaseMapper instead of IMapDefinition?

  • Ismail Mayat 4366 posts 9472 karma points MVP 2x admin c-trib
    Jul 15, 2019 @ 09:34
    Ismail Mayat
    0

    Damiaan,

    Tried that and now the error moves to when i view my property editor:

    Don't know how to map Umbraco.Core.Models.Membership.IUserGroup to Our.Umbraco.RedirectsViewer.Models.UserGroupDisplay

  • Emma Garland 34 posts 109 karma points MVP 2x c-trib
    Jul 17, 2019 @ 13:14
    Emma Garland
    101

    Hi Ismail

    I have struggled with the same thing today, and found that I got a bit further (although not 100% this is correct) when I replaced:

    composition.WithCollectionBuilder<MapperCollectionBuilder>().Add<UserGroupProfile>();
    

    with

    composition.WithCollectionBuilder<MapDefinitionCollectionBuilder>().Add<UserGroupProfile>();
    

    (leaving the interface for the UserGroupProfile to implement as IMapDefinition)

    Hope that helps? Once I've got this working completely I'll post to confirm. If so I'll look at maybe doing a PR to update the documentation.

    Thanks

    Emma

  • Emma Garland 34 posts 109 karma points MVP 2x c-trib
    Jul 17, 2019 @ 13:18
    Emma Garland
    0

    Just to note, the next issue I am encountering is Don't know how to create X instances where X is my target to map to.

  • Emma Garland 34 posts 109 karma points MVP 2x c-trib
    Jul 17, 2019 @ 13:26
    Emma Garland
    0

    mapper.Define<Y, X>((source, context) => new X() { TestString = source.TestString; });

    Sorted it, in terms of what to map. Now to customise what to map!

    Hope changing the CollectionBuilder sorts it for you too

    • Emma
Please Sign in or register to post replies

Write your reply to:

Draft