public static DataTable CreateDataTable<T>(
this IEnumerable<T> query,
string tableName) {
DataTable table = new DataTable(tableName);
var fields = typeof(T).GetProperties();

// vytvoen sloupc
foreach (var field in fields) {
DataColumn column = new DataColumn(field.Name);
column.AllowDBNull =
(typeof( T ).IsSubclassOf( typeof( ValueType ) ) ) ?
IsNullableType( typeof( T ) ) :
true;
table.Columns.Add(column);
}

// nakoprovn dk
foreach (var row in query) {
object[] values = new object[fields.Length];
for( int i = 0; i < values.Length; i++ ) {
	values[i] = fields[i].GetValue(row, null);
}
table.Rows.Add(values);
}
return table;
}
