如何映射已经映射到源对象的强类型属性?

时间:2018-08-27 10:45:02

标签: automapper

如何映射已经映射到源对象的属性?我不想使用继承

    public class ParentMappingProfile: Profile{
      public ParentMappingProfile(){
          CreateMap<App.Context.Person,Parent>()
           /*this line works*/
          .ForMember(dest=>dest.Children,
             opt=>opt.MapFrom(src=>src.IdInversedNavigation))
            /*this does not work, person remains null*/
          .ForMember(dest=>dest.Person, opt=>opt.MapFrom(src=>src));
      }
    }

其他课程

    public class PersonBase{
       public int id{get;set;}
       public string Name{get;set;}
    }
    public class PersonMappingProfile: Profile{
      public PersonMappingProfile(){
          CreateMap<App.Context.Person,PersonBase>()
          ForMember(...);
      }
    }
    public class Parent{
       public PersonBase Person{get;set;};
       public IEnumerable<PersonBase> Children{get;set;};
    }

0 个答案:

没有答案