开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜