This is a bit crude and could require som nullchecking but this should work :)
public class RowMapper
{
public void AddToDb(DataTable dataTable)
{
using (var db = new Entities())
{
for (int idx = 0; idx < dataTable.Rows.Count; idx++)
{
GL_InputTableRow newrow;
GetMapAblesInRow(dataTable, idx, out newrow);
db.GL_InputTable.Add(newrow);
}
db.SaveChanges();
}
}
private void GetMapAblesInRow(DataTable dataTable, int idxRow, out GL_InputTableRow outEntityTableRow)
{
var efTable = new GL_InputTableRow();
Type t = typeof(GL_InputTableRow);
PropertyInfo[] propInfos = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (DataColumn clmn in dataTable.Columns)
{
PropertyInfo pi = propInfos.FirstOrDefault(p => p.Name == clmn.ColumnName);
if (pi != null && pi.CanWrite)
{
pi.SetValue(efTable, dataTable.Rows[idxRow][clmn.ColumnName].ToString());
}
}
outEntityTableRow = efTable;
}
}