我在 .NET CORE 2.2 項目中使用 AutoMapper。我得到這個異常:缺少類型映射配置或映射不受支持。映射類型:SaveFridgeTypeModel -> FridgeType College.Refrigirator.Application.SaveFridgeTypeModel -> College.Refrigirator.Domain.FridgeType在這一行:var fridgeType = _mapper.Map<SaveFridgeTypeModel, FridgeType>(model);這是 FridgeType 類的定義:public class FridgeType : IEntity , IType{ public FridgeType() { Fridges = new HashSet<Fridge>(); } public int ID { get; set; } //Description input should be restricted public string Description { get; set; } public string Text { get; set; } public ICollection<Fridge> Fridges { get; private set; }}這是 SaveFridgeTypeModel 類的定義:public class SaveFridgeTypeModel{ public string Description { get; set; } public string Text { get; set; }}我添加這一行: services.AddAutoMapper(typeof(Startup));Startup類中的ConfigureServices函數。更新我忘記在帖子中添加映射配置。這是映射配置類:public class ViewModelToEntityProfile : Profile{ public ViewModelToEntityProfile() { CreateMap<SaveFridgeTypeModel, FridgeType>(); }}知道為什么我會得到上面的異常嗎?
為什么當我嘗試使用 AutoMapper 時出現異常?
慕無忌1623718
2024-01-20 21:44:50