Repository navigation
Create dynamic map from data stored in a database #2328
Replies: 1 comment
|
You can load the aliases from the table before creating the map. Map(record => record.EventId)
.Name(catalog.NamesFor(nameof(ImportRecord.EventId)));Then register the map instance containing the loaded aliases with This complete example includes your three-column table and all 18 aliases. It uses SQLite for a local demonstration and CsvHelper 33.1.0. Its checks first reject an unknown The table's |
Uh oh!
There was an error while loading. Please reload this page.
I have a SQL table that has the following columns: CsvColumnName | PropertyName | DataType
and the following data:
CatalogueTypeCode|CatalogueTypeCode|String
CatalogueType|CatalogueTypeCode|String
Catalogue|CatalogueTypeCode|String
TypeCode|CatalogueTypeCode|String
DayInPeriod|DayInPeriod|String
EventID|EventId|String
Event|EventId|String
Eve|EventId|String
EveId|EventId|String
MeanLoss|MeanLossAmount|Decimal
Perspvalue|MeanLossAmount|Decimal
Loss|MeanLossAmount|Decimal
RegionalPeril|PerilZone|String
PerilZone|PerilZone|String
Region|PerilZone|String
Period|Period|String
PeriodId|Period|String
Year|Period|String
I want to retrieve this data back and create a map on the fly.
So if it was hard coded, it would look something like this:
Map(m => m.EventId).Name("EventId", "Event", "Eve", "EveId");
Map(m => m.Period).Name("Period", "PeriodId", "Year");
Map(m => m.MeanLossAmount).Name("MeanLoss", "Perspvalue", "Loss");
Map(m => m.DayInPeriod).Name("DayInPeriod");
Map(m => m.PerilZone).Name("RegionalPeril", "PerilZone", "Region");
Map(m => m.CatalogueTypeCode).Name("CatalogueTypeCode", "CatalogueType", "Catalogue", "TypeCode");
I'm trying to do it dynamically because if the users start using a new column header in their CSV files, I would prefer to add it to the database rather than have to recompile and redeploy.
Any suggestions or help is greatly appreciated..
All reactions