Skip to content

Instantly share code, notes, and snippets.

@wellwind
Created December 13, 2015 05:23
Show Gist options
  • Save wellwind/ea43d5154de40fbaeb19 to your computer and use it in GitHub Desktop.
Save wellwind/ea43d5154de40fbaeb19 to your computer and use it in GitHub Desktop.
使用AutoMapper來將DataTable轉成強行別List<T>
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