开发者

cannot map from one entity to another automapper exception throwing?

开发者 https://www.devze.com 2023-03-10 01:44 出处:网络
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.

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

精彩评论

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