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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Automapper 不適用于嵌套對象

Automapper 不適用于嵌套對象

C#
元芳怎么了 2021-10-24 16:35:16
我目前使用 .net core 2.1 并嘗試對嵌套對象使用 automapper 將模型轉(zhuǎn)換為 dto 并將 dto 轉(zhuǎn)換為模型。當每個字段都被正確映射時,關系映射就會出現(xiàn)問題??ublic class DropdownValue{    public int Id { get; set; }    public string Value { get; set; }    public int PropertyId { get; set; }    public Property Property { get; set; }}public class Property{    public int Id { get; set; }    public string Title { get; set; }    public ValueTypes ValueType { get; set; }    public InputTypes InputType { get; set; }    public List<DropdownValue> DropdownValues { get; set; }}托斯public class DropdownValueDto{    public int Id { get; set; }    public string Value { get; set; }    public PropertyDto Property { get; set; }}public class PropertyDto{    public int Id { get; set; }    public string Title { get; set; }    public InputTypes InputType { get; set; }    public ValueTypes ValueType { get; set; }}映射器public class MappingProfile : Profile{    public MappingProfile()     {        CreateMap<Property, PropertyDto>();        CreateMap<DropdownValue, DropdownValueDto>();    }}在處理程序中的使用_mapper.Map<List<Models.DropdownValue>, List<DropdownValueDto>>(dropdownValues)
查看完整描述

2 回答

?
12345678_0001

TA貢獻1802條經(jīng)驗 獲得超5個贊

//Models


public class DropdownValue

{

    public int Id { get; set; }

    public string Value { get; set; }

    public int PropertyId { get; set; }

    public Property Property { get; set; } = new Property();

}


public class Property

{

    public int Id { get; set; }

    public string Title { get; set; }

    public ValueTypes ValueType { get; set; } = new ValueTypes();

    public InputTypes InputType { get; set; } = new InputTypes();

    public List<DropdownValue> DropdownValues { get; set; } = new List<DropdownValue>();

}

//Dtos


public class DropdownValueDto

{

    public int Id { get; set; }

    public string Value { get; set; }

    public PropertyDto Property { get; set; } = new PropertyDto();

}


public class PropertyDto

{

    public int Id { get; set; }

    public string Title { get; set; }

    public InputTypes InputType { get; set; } = new InputTypes();

    public ValueTypes ValueType { get; set; } = new ValueTypes();

}


查看完整回答
反對 回復 2021-10-24
?
婷婷同學_

TA貢獻1844條經(jīng)驗 獲得超8個贊

我總是在 .net 4x 框架項目中使用automapper映射工具,但是當我開發(fā) .net 核心項目時,我總是使用并推薦mapster映射工具。它非??焖俸秃唵?!基準測試結(jié)果它還可以解決您的問題。您可以在下面查看示例用法。


首先創(chuàng)建一個映射器類。


public static class Mapper

{

    public static void CreateMap()

    {

        TypeAdapterConfig<Property, PropertyDto>

            .NewConfig();


        TypeAdapterConfig<DropdownValue, DropdownValueDto>

            .NewConfig();

    }

}

啟動時初始化


    public Startup(IHostingEnvironment env)

    {

        // other stuffs


        // Mapping

        Mapper.CreateMap();

    }

用法


dropdownValues.Adapt<List<Models.DropdownValue>, List<DropdownValueDto>>()


查看完整回答
反對 回復 2021-10-24
  • 2 回答
  • 0 關注
  • 287 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號