1

My Class Model Structure is like below

      public class ParentModel
        {
            .
            .

            public IEnumerable<ChildModel> child { get; set; }

        }

From DB i will be getting IEnumerable<Parent> and am mapping that to Model before passing it to View and Each parent will have IEnumerable<Child>

I used Automapper to copy from Parent Entity to ParentModel using the below code and it works fine

     Mapper.CreateMap<Parent, ParentModel>();
        Mapper.CreateMap<Child, ChildModel>();
        IEnumerable<ParentModel> parent = Mapper.Map<IEnumerable<Parent>, IEnumerable<ParentModel>>((IEnumerable<Parent>)Object);

Now i making some logical changes(Business need) and want to split the Child model like parentmodel will contain ChildViewModel and childViewmodel will contain IEnumerable<ChildModel>

public class ParentModel
    {
        .
        .

        public ChildViewModel child { get; set; }

    }
     public class ChildViewModel
    {
        .
        .

        public IEnumerable<ChildModel> child { get; set; }

    }

How can i achieve this from my Parent Entity to parent model using AutoMapper ?

Thanks

Peru
  • 2,871
  • 5
  • 37
  • 66

0 Answers0