The solution was to create a new object and map the property manually. The Enum was handled this way:
MyEnumProperty = (MyEnumProperty)Convert.ToInt32(c["ColumnNameInExcel"])
Question
I'm having an issue handling one column of the Excel file I'm trying to import to my database. The property refers to an Enum model. I tried putting integers values (referring to the Enum index) or the string value themselves but obviously it doesn't work.
How would I go about handling this using (I assume) the AddTransformation method?
La solution 3
The solution was to create a new object and map the property manually. The Enum was handled this way:
MyEnumProperty = (MyEnumProperty)Convert.ToInt32(c["ColumnNameInExcel"])
Autres conseils
I was able to accomplish this by mapping the value from the cell to the enum value in the transformation function:
excel.AddTransformation<DataImportJob>(x => x.Status, cellValue =>
{
switch (cellValue)
{
case "Failed":
return JobStatusType.Failed;
case "InProgress":
return JobStatusType.InProgress;
case "Scheduled":
return JobStatusType.Scheduled;
case "Success":
return JobStatusType.Success;
default:
return JobStatusType.Undefined;
}
});
Yea, try the AddTransformation
method and see if that works.
I tried the AddTransformation method with Invalid cast from Double to enum issue.
excelFile.AddTransformation<Table>(x => x.Company, cellValue => (MyEnumProperty)Convert.ToInt32(cellValue));