public virtual DataTable GetDataTable( Dictionary <string, object> properties, bool exactMatch, bool shapeColumnNames, List <string> topColumnNames, SearchType searchType) { DataTable result = EntityReaderGeneric <E> .GetDataTable(shapeColumnNames, topColumnNames); List <E> entities = GetEntitiesByProperties(properties, exactMatch, searchType); foreach (E e in entities) { DataRow row = EntityReaderGeneric <E> .PopulateDataRow(e, result.NewRow(), shapeColumnNames); result.Rows.Add(row); } return(result); }
public virtual Dictionary <K, E> DataTableToDictionary(DataTable table) { Dictionary <K, E> result = new Dictionary <K, E>(); foreach (DataRow row in table.Rows) { E e = EntityReaderGeneric <E> .PopulateFromDataRow(Activator.CreateInstance <E>(), row); K surrogateKey = GetSurrogateKeyValue(e); if (result.ContainsKey(surrogateKey)) { throw new Exception(string.Format( "May not load more than one {0} with the same Id {1}.", typeof(E).FullName, surrogateKey.ToString())); } result.Add(surrogateKey, e); } return(result); }
public virtual void ImportFromCsv(string filePath, bool shapeColumnNames) { Clear(); _entities = DataTableToDictionary( CsvParser.ParseFromFile(filePath, true, EntityReaderGeneric <E> .GetDataTable(shapeColumnNames).Columns.Count)); }