-
Hi, I'm importing a string into a SQL table with a max length of 50. Is it possible to enforce a max length on a string value in one column with a mapping? If the string being imported is longer than 50 characters I would want to import the first 50 characters. |
Beta Was this translation helpful? Give feedback.
Answered by
JoshClose
Jan 11, 2023
Replies: 1 comment 1 reply
-
No. You could write a custom converter to do it though. public class TruncateStringConverter : StringConverter
{
public override object ConvertFromString(string text, IReaderRow row, MemberMapData memberMapData)
{
var s = base.ConvertFromString(text, row, memberMapData) as string;
return s == null ? s : s.Substring(0, 50);
}
} You can apply that via a mapping like Map(m => m.StringProperty).TypeConverter<TruncateStringConverter>(); Or globally for all strings like csv.Context.TypeConverterCache.AddConverter<string>(new TruncateStringConverter()); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
R1Fo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No. You could write a custom converter to do it though.
You can apply that via a mapping like
Or globally for all strings like