因为我们每次和数据库交互都需要转换为泛型,所以将这个方法抽象出来,放在D层一遍调用,和sqlhelper类的作用相似
'**********************************************
'说明:将DataTable转化为泛型集合
'命名空间:DAL
'机器名称:晓
'创建日期:2015/2/23 11:13:28
'作者:郑浩
'版本号:V1.00
'**********************************************
Imports System.Collections.Generic '增加泛型的命名空间
Imports System.Reflection '引入反射:为了使用PropertyInfo
Public Class ConvertGenericsHelper
'将datatable转化为泛型集合
Public Shared Function convertToList(Of T As {New})(ByVal dt As DataTable) As IList(Of T)
'注意:convertToList(Of T As {New}) 这里的new是用来约束T的,必须有,不然new T的时候会出现错误
Dim myList As New List(Of T) '定义最终返回的集合
Dim myTpye As Type = GetType(T) '得到实体类的类型名
Dim dr As DataRow '定义行集
Dim tempName As String = String.Empty '定义一个临时变量