-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constant doesn't work when there is no field in the CSV #1030
Comments
Why do I want to do this? I'm letting users define their own mappings in software then storing them in a database so they can use their own CSV file formats. Sometimes their file formats don't have all the fields. In that case the user wants to put in a constant, and that field won't be in the incoming CSV file. |
I'll put this as a feature request. When writing you don't even have to specify a property and it works. I think this might have just been an oversight. For now, you can do this. Map(m => m.Name).ConvertUsing((IReaderRow row) => "the constant"); |
Interestingly, A passing test (for Reading\ConstantTests.cs, as above):
|
Came across this bug today as I tried to map a CSV to a POCO and add a hard-coded field. I could do it after the fact, but it just seemed cleaner to do it at the point of deserialization, where all of the other properties are set. Maybe I'll try to pick up where #1252 left off. |
I needed this feature today in order to add a Guid FileId to each record as it was being imported, to identify which import file generated the record. Dealing with lots of data so enumerating the records to fix them up is not desirable. Used this workaround: |
Looks like this works in the current version. |
I'm trying to write a map that always fills in one field in my output class with a constant value. However I can't, it only works when there is a field in the incoming csv file.
Here's a test for what I want to do. (an additional test in ConstantTests.cs)
(for reference, TestStringMap looks like:
)
The text was updated successfully, but these errors were encountered: