Last active
April 1, 2016 06:57
-
-
Save tkouba/23e5ba4a4e63e4d569e32e1d9b38680f to your computer and use it in GitHub Desktop.
TimeSpanValueConverter for DevExpress XPO - save TimeSpan to database in seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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