Skip to content

Issue binding data to model? #85

Answered by MarkPflug
dgomez-listrak asked this question in Q&A
Discussion options

You must be logged in to vote

It looks like the issue is that your csv file doesn't have headers (HasHeaders = false). The binder doesn't know what to do with the data, since it isn't explicitly labeled. You can fix this by defining the column schema explicitly.

public static IEnumerable<receiptModel> GetRecords(string csvFile)
        {
            var schema = Schema.Parse("storeId,registerId,transNo,lineItem,lineType,receiptLine");

            var options = new CsvDataReaderOptions
            {
                HasHeaders = false,
                Schema = new CsvSchema(schema),
            };

            using var csv = CsvDataReader.Create(csvFile, options);
            var binder = DataBinder.Create<receiptMode…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@dgomez-listrak
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dgomez-listrak
Comment options

Answer selected by dgomez-listrak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants