缺少类型映射配置或JsonPatchDocument不支持的映射

时间:2020-09-14 14:43:55

标签: .net automapper

尝试使用Automapper 10进行映射。在9.1上运行良好。 创建的地图-

CreateMap(typeof(JsonPatchDocument<>), typeof(JsonPatchDocument<>)).ReverseMap();
CreateMap(typeof(Operation<>), typeof(Operation<>)).ReverseMap()

按如下所示加载地图

cfg.AddMaps(assemblyList);
cfg.AddProfiles(new List<Profile>(){new AutoMappingProfile()});

这就是我的映射方式。实体类型在运行时动态评估。

var sourceType = jsonPatchDocument.GetType();
var destinationType = typeof(JsonPatchDocument<>).MakeGenericType(entityType);
var method = GetMethod(nameof(Repository.Patch), new[] { entityType });
Mapper.Map(jsonPatchDocument, sourceType, destinationType);

这将引发以下错误

Test method Sfc.Wms.Data.UoW.Tests.Integration.DbUnitOfWorkTest.TestPatchByDictionary threw exception: 
AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.

Mapping types:
Object -> Object
System.Object -> System.Object
Stack Trace: 
    lambda_method(Closure , Object , Object , ResolutionContext )
    DbUnitOfWork.Patch[TDto](JsonPatchDocument`1 jsonPatchDocument) line 450
    DbUnitOfWork.Patch[TDto,TKey](TKey key, IDictionary`2 updateDictionary) line 431
    DbUnitOfWorkTest.TestPatchByDictionary() line 474

            

0 个答案:

没有答案