第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

為什么當(dāng)我嘗試使用 AutoMapper 時(shí)出現(xiàn)異常?

為什么當(dāng)我嘗試使用 AutoMapper 時(shí)出現(xiàn)異常?

PHP
慕無忌1623718 2024-01-20 21:44:50
我在 .NET CORE 2.2 項(xiàng)目中使用 AutoMapper。我得到這個(gè)異常:缺少類型映射配置或映射不受支持。映射類型: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函數(shù)。更新我忘記在帖子中添加映射配置。這是映射配置類:public class ViewModelToEntityProfile : Profile{    public ViewModelToEntityProfile()    {        CreateMap<SaveFridgeTypeModel, FridgeType>();    }}知道為什么我會(huì)得到上面的異常嗎?
查看完整描述

2 回答

?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

在使用 DI 注冊(cè)自動(dòng)映射器時(shí),您需要使用映射所在程序集中的類型。

AddAutomapper(typeof(ViewModelToEntityProfile));

如果您有多個(gè)帶有地圖的程序集 - 您可以使用另一個(gè)重載:

AddAutomapper(typeof(ViewModelToEntityProfile), typeof(SomeOtherTypeInOtherAssembly));



查看完整回答
反對(duì) 回復(fù) 2024-01-20
?
蕭十郎

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊

Startup.cs創(chuàng)建映射配置類后,您需要在如下所示中添加 AutoMapperConfiguration :


  public void ConfigureServices(IServiceCollection services) {

    // .... Ignore code before this


   // Auto Mapper Configurations

    var mappingConfig = new MapperConfiguration(mc =>

    {

        mc.AddProfile(new ViewModelToEntityProfile());

    });


    IMapper mapper = mappingConfig.CreateMapper();

    services.AddSingleton(mapper);


    services.AddMvc();

}


查看完整回答
反對(duì) 回復(fù) 2024-01-20
  • 2 回答
  • 0 關(guān)注
  • 179 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)