Created
December 13, 2015 05:23
-
-
Save wellwind/ea43d5154de40fbaeb19 to your computer and use it in GitHub Desktop.
使用AutoMapper來將DataTable轉成強行別List<T>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MapperHelper | |
{ | |
public static IList<T> GetDataFromDataTable<T>(DataSet dataSet, int dataTableIndex) | |
{ | |
var table = dataSet.Tables[dataTableIndex]; | |
using (var reader = dataSet.CreateDataReader(table)) | |
{ | |
return Mapper.Map<IList<T>>(reader).ToList(); | |
} | |
} | |
public static IList<T> GetDataFromDataTable<T>(DataSet dataSet, string tableName) | |
{ | |
var table = dataSet.Tables[tableName]; | |
using (var reader = dataSet.CreateDataReader(table)) | |
{ | |
return Mapper.Map<IList<T>>(reader).ToList(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment