开发者

AutoMapper Custom Collections

I am getting an AutoMapper Exception when i try to Map my DomainModel to ViewModel,

Here is my Domain Model Class,

public class Source{

public string Name {get;set;}

..............

public CustomCollection EmpDetails {get;set;}

}

public class CustomCollection:CollectionBase,IEnumerable<ClassA> {

public CustomCollection{}

public i开发者_JAVA技巧nt Add(ClassA classA)

{
  return List.Add(classA);
}

..........

}

public class ClassA{

public string EmpNumber {get;set;}

public string EmpName {get;set;}

public string Designation {get;set;}

}

Here is my ViewModel

public class SourceDTO{

public string Name {get;set;}

public IList<EmpDTO> EmpDetails {get;set;}


}

public class EmpDTO{

public string EmpNumber {get;set;}

public string EmpName {get;set;}

public string Designation {get;set;}

}

Here is my AutoMapper Code,

AutoMapper.Mapper.CreateMap<Source, SourceDTO>()
            .ForMember(x => x.EmpDetails, y => y.MapFrom(src => src.EmpDetails));

I am getting error here, It doesn't say any detail inner exceptions,

I hope someone can help us out.


You need to include a mapping to go from ClassA to EmpDTO:

Mapper.CreateMap<ClassA, EmpDTO>();

And you should be all set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜