I've based the mappings for my CSV file based off the official docs here: https://joshclose.github.io/CsvHelper/getting-started
here are my class I'm using
public class DropShippperCSV
{
public string PurchaseOrderNumber { get; set; }
public int ReleaseNumber { get; set; }
public int LineNumber { get; set; }
public string DeliveryCompanyName { get; set; }
public string DeliveryCompanyTrackingNumber { get; set; }
}
public class DropShippperCSVMap : ClassMap<DropShippperCSV>
{
public DropShippperCSVMap()
{
Map(m => m.PurchaseOrderNumber).Column("Delivery Company Tracking Number");
Map(m => m.ReleaseNumber).Column("Release Number");
Map(m => m.LineNumber).Column("Line Number");
Map(m => m.DeliveryCompanyName).Column("Delivery Company Name");
Map(m => m.DeliveryCompanyTrackingNumber).Column("Delivery Company Tracking Number");
}
}
then calling on it like so
var reader = new StreamReader(file.OpenReadStream());
var csv = new CsvReader(reader);
csv.Configuration.RegisterClassMap<DropShippperCSVMap>();
var records = csv.GetRecords<DropShippperCSV>().ToList();
and I'm getting this error
Error CS0311 The type 'DropShippperCSVMap' cannot be used as type parameter 'TMap' in the generic type or method 'IReaderConfiguration.RegisterClassMap()'. There is no implicit reference conversion from 'DropShippperCSVMap' to 'CsvHelper.Configuration.ClassMap'.
I've based directly off the offical docs and I can't tell what I did wrong
Use csv.Context.RegisterClassMap<DropShippperCSVMap>(); instead of csv.Configuration.RegisterClassMap<DropShippperCSVMap>();.
I droped FluentNHibernate and RegisterClassMap entirely and used CsvHelper.Configuration.Attributes Name attribute to do the mapping instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With