1

I want to map sub categories model which has foreign key for category model to categories model using "valueinjecter" mapping.
I have made "viewmodel" and write list<category> type property in it and now I want to bind sub categories to it.

Tables are as follows according to your specifications Categories table:

        Id Name
        1 gender
        2 Role

Sub Categories table:

         Id CategoryId Name
         1  1          Male
         2  1          Femal
         3  2          admin
         4  2          user
Sa Nuj
  • 103
  • 10

1 Answers1

0

you need something like this:

Mapper.AddMap<Customer, CustomerInput>(src =>
{
    var res = new CustomerInput();
    res.InjectFrom(src); // maps simple properties with same name and type
    res.Coll = src.Collection.Select(srcItem => Mapper.Map<CollItemResType>(srcItem)
    return res;
});
Omu
  • 69,856
  • 92
  • 277
  • 407