【问题标题】:Automapper Datatable to ListAutomapper 数据表到列表
【发布时间】:2016-08-14 18:49:38
【问题描述】:

我想使用自动映射器将我的数据表映射到列表。我尝试使用下面的代码,但它不起作用,我遇到了错误。

var data = GetDataTableResult();
var result = Mapper.Map<IDataReader, IList<RollCall>(data.CreateDataReader()); 

public class RollCall
{
    public long Id { get; set; }
    public string CreationUserId { get; set; }
    public DateTime CreationTs { get; set; }
    public string LastChangeUserId { get; set; }
    public DateTime LastChangeTs { get; set; }
    public byte StatusType { get; set; }
    public DateTime EntryTs { get; set; }
    public int ClientId { get; set; }
    public int RollcallId { get; set; }
    public int VehicleId { get; set; }
    public double Quantity { get; set; }
    public double OpeningOdo { get; set; }
    public double ClosingOdo { get; set; }
    public int OrderId { get; set; }
}

缺少类型映射配置或不支持的映射。 映射类型: IDataReader -> IList1 System.Data.IDataReader -> System.Collections.Generic.IList1[[SampleDemo.RollCall, SampleDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] 目的地路径: 列表`1 源值: System.Data.DataTableReader

【问题讨论】:

    标签: c# datatable automapper


    【解决方案1】:

    首先Reset mapper和Creat Map,然后做mapper,把IList改为List:

    AutoMapper.Mapper.Reset();
    AutoMapper.Mapper.CreateMap<IDataReader, RollCall>();
    result = AutoMapper.Mapper.Map<IDataReader, List<RollCall>>(data.CreateDataReader());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-12
      • 2012-02-12
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 2022-01-02
      • 2016-10-16
      相关资源
      最近更新 更多