automapper - 动态地图法线贴图之间的区别 [英] The differences between a normal map with dynamic map - automapper

查看:191
本文介绍了automapper - 动态地图法线贴图之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是下面的代码之间的差异;

What are the differences between the codes below;

    List<Ogrenci> ogrenci = AutoMapper.Mapper.DynamicMap<IDataReader,   List<Ogrenci>>((dt.CreateDataReader()));

    var ogr = AutoMapper.Mapper.Map<IDataReader, IList<Ogrenci>>(dt.CreateDataReader());

当我尝试使用下面的代码;

When i try to use the code below;

 AutoMapper.Mapper.CreateMap<IDataReader, Ogrenci>().ForMember(dest => dest.Numarasi, opt => opt.MapFrom(src => Convert.ToInt32(src["Numara"])))
            .ForMember(dest => dest.Adi, opt => opt.MapFrom(src => Convert.ToString(src["Ad"])))
            .ForMember(dest => dest.Soyadi, opt => opt.MapFrom(src => Convert.ToString(src["Soyad"])));

        List<Ogrenci> ogrenci = AutoMapper.Mapper.DynamicMap<IDataReader, List<Ogrenci>>((dt.CreateDataReader()));
        var ogr = AutoMapper.Mapper.Map<IDataReader, IList<Ogrenci>>(dt.CreateDataReader());



我不能使用使用下面的代码;

I can not use use the code below;

  List<Ogrenci> ogrenci = AutoMapper.Mapper.DynamicMap<IDataReader, List<Ogrenci>>((dt.CreateDataReader()));



但我可以使用下面的代码;

but i can use the code below ;

   var ogr = AutoMapper.Mapper.Map<IDataReader, IList<Ogrenci>>(dt.CreateDataReader());



你有什么建议?

What are your suggestions?

感谢你。

推荐答案

当你不知道在编译时的源类型AutoMapper DynamicMap使用。究其原因,你不能使用

DynamicMap in AutoMapper is used when you don't know the source type at compile time. The reason you can't use

List<Ogrenci> ogrenci = AutoMapper.Mapper.DynamicMap<IDataReader, List<Ogrenci>>((dt.CreateDataReader()));



是因为DynamicMap不需要你指定源类型,只有目标类型。

is because DynamicMap doesn't need you to specify the source type, only the destination type.

AutoMapper功能:动态映射

这篇关于automapper - 动态地图法线贴图之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆