Copied to clipboard

Flag this post as spam?

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


  • Himanshu Tripathi 5 posts 106 karma points
    Feb 24, 2020 @ 20:24
    Himanshu Tripathi
    0

    Hi, I'm looking to use some Mapping technique in Umbraco. I've a custom database using Entity Framework (EF) and Umbraco APIs, this is being used to implement the business logic for a membership portal, and not the CMS functionality in CMS. The business logic runs using the custom database.

    the Umbraco APIs are called in the front-end using AngularJS. In the APIs I want to map the data queried from custom database using Entity Framework and Map it to ViewModels that I've defined.

    What's the best way of doing it? I've looked at the UmbracoMapper - https://our.umbraco.com/documentation/Reference/Mapping/ but not sure how to use it for Mapping the EF models to my defined View Models. I also tried https://github.com/AndyButland/UmbracoMapper, using code like:

            var courses = courseDb.GetCourses();
            var mapper = new UmbracoMapper();
            var model = new List<CourseVM>();
    
            mapper.MapCollection(courses , model);
    

    but it only seems to support mapping of IPublishedcontent.

    Is there a way to use something similar to AutoMapper in Umbraco. Please all you experts I really need to find a way to do this. Please help...

    Thanks, Himanshu

  • Himanshu Tripathi 5 posts 106 karma points
    Mar 16, 2020 @ 18:03
    Himanshu Tripathi
    101

    Just if someone comes to this thread. You don't need to use Umbracomapper, I managed to use the Automapper directly in the code.

    Following is the example code I used:

                var users = userDb.GetUsers().ToList();
    
            //get VM
            var config = new MapperConfiguration(cfg => {
                cfg.CreateMap<User, UserVM>();
            });
            IMapper mapper = config.CreateMapper();
            var model = mapper.Map<List<User>, List<UserVM>>(users);
    
Please Sign in or register to post replies

Write your reply to:

Draft