具有数据表的自动映射器

时间:2016-02-20 10:08:17

标签: vb.net c#-4.0 automapper-4

任务:我需要将包含与CLass Person属性相同的列名的datatable的记录映射到Person类对象的List中。

对于此“Person”类,具有FN和LN属性。 和datatable包含“FN”和“LN”列名, 现在,数据表的记录需要映射到“Person”类的列表

现在,下面的代码用于通过automapper 4.0创建动态映射, 所以现在的问题是当我应用AutoMapper.Mapper.DynamicMap时 昏暗的人作为列表(人)= AutoMapper.Mapper.DynamicMap(IDataReader,List(Of Person))(table.CreateDataReader()) 它让我在“人物”对象中数为0。

代码:

/创建课程

Public Class Person
  Public Property FN As String
  Public Property LN As String
End Class

/创建数据表

     Dim table = New DataTable()
     table.Columns.Add("FN", GetType(String))
    table.Columns.Add("LN", GetType(String))
    table.Rows.Add("Jeff", "Barnes")
    table.Rows.Add("George", "Costanza")
    table.Rows.Add("Stewie", "Griffin")
    table.Rows.Add("Stan", "Marsh")
    table.Rows.Add("Eric", "Cartman")

/需要将数据表的记录映射到Person类属性。

Dim people As List(Of Person)=AutoMapper.Mapper.DynamicMap(Of IDataReader,List(Of Person))(table.CreateDataReader())

** /但问题是,我得到了0个人的名单,我在这段代码中遗漏了一些东西。 ****

0 个答案:

没有答案