Relative Content

Tag Archive for csvhelper

With CsvHelper, how do I make it use string.Empty instead of Null for missing varchar fields?

Say I have a c# class “Person” with a property named “FirstName”. In the database, FirstName is a VARCHAR(100) NOT NULL field. When CsvHelper imports a CSV that lacks a FirstName field, I need it to use a default value of string.Empty for that field rather than Null. I don’t want to create a custom Map for each record type because I have many of those, so how can I configure CsvHelper to automatically use string.Empty instead of Null when it encounters a missing varchar field on any record type it encounters?