Skip to content

Instantly share code, notes, and snippets.

@tkouba
Last active April 1, 2016 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkouba/23e5ba4a4e63e4d569e32e1d9b38680f to your computer and use it in GitHub Desktop.
Save tkouba/23e5ba4a4e63e4d569e32e1d9b38680f to your computer and use it in GitHub Desktop.
TimeSpanValueConverter for DevExpress XPO - save TimeSpan to database in seconds
public class TimeSpanValueConverter : ValueConverter
{
public override Type StorageType { get { return typeof(Int32); } }
public override object ConvertToStorageType(object value)
{
if (!(value is TimeSpan)) return null;
return Convert.ToInt32(Math.Truncate(((TimeSpan)value).TotalSeconds));
}
public override object ConvertFromStorageType(object value)
{
if (!(value is Int32)) return null;
return TimeSpan.FromSeconds((Int32)value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment