cannot map from one entity to another automapper exception throwing?
I have tried to get from resources from database and tried to map to another model class but was unable to do .and it is showing an automapper exception.
Trying to map RM.Easicreate.Data.Entities.Resource to RM.Easicreate.Core.DataContracts.ResourceDataContract. Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.
My code looks like this.
Resource res= resources.FirstOrDefault();
ResourceDataContract r = Mapper.Map<Resource, ResourceDataContract>(res);
and i have configured automapper in my bootstaper like this
Mapper.CreateMap<Resource, ResourceDataContract>();
Mapper.AssertConfigurationIsValid();
but it seems to be not working? why is that s开发者_开发知识库o?
If there is no data in your table FirstOrDefault will return null, not 100% sure but sending in a null value may give that exception.
精彩评论