Automapper mapping list becomes 0

后端 未结 3 1482
猫巷女王i
猫巷女王i 2020-12-19 04:09

I\'m mapping a list to another list with Automapper, but it seems that my items are not copied.

Here is my code:

var roles = userRepo.GetRoles(null).         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 04:17

    In my case, I had the (parent) type mapping configured correctly but I didn't add the mappings for the child records, so for this:

    class FieldGroup
    {
        string GroupName { get; set; }
        ...
        List fields { get; set; }
    }
    

    I had to add the second mapping:

    cfg.CreateMap();
    cfg.CreateMap(); << was missing
    

提交回复
热议问题