2 回答

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();
}

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>>()
- 2 回答
- 0 關注
- 287 瀏覽
添加回答
舉報