AutoMapper.Mapper.CreateMap()' is obsolete

前端 未结 3 366
忘了有多久
忘了有多久 2020-12-31 04:58

I have to classes Like

class A
{
 public int id {get; set;}
}

class B
{
 public C c {get; set;}
}

class C
{
 public int id {get; set;}
 public string Name          


        
3条回答
  •  心在旅途
    2020-12-31 05:44

    Finally I found the resolution. I was doing: Mapper.Initialize{ Mapping field from source to destination } in the App_start and adding this file to the global.asax--> Application_Start() --> GlobalConfiguration.

    I need to add one more line inside my Mapper.Initialize which is cfg.CreateMissingTypeMaps = true;

    Now this code will work for explicit mapping where two classes don't have the same structure and names of properties.

    Apart from this, if we need to map properties of two class with the same structure the code Mapper.map(source, destination) will also work, which was not working earlier.

    Let me know if someone is having difficulty with the solution. Thanks all for the above reply.

提交回复
热议问题