Subsonic ignoring TimeSpan property
For some reason the开发者_StackOverflow TimeSpan property on my class is not being persisted into the database by Subsonic it is simply being ignored!? All other properties are being saved OK. I am using SimpleRepository and RunMigrations, Subsonic v3.0.0.3.
public TimeSpan Time { get; set; }
Are TimeSpans not supported?
TimeSpan is not a valid 2005/2008 SQL data type.
Store it as a numeric based SQL data type. Convert your TimeSpan to an appropriate duration based on the accuracy you require:
// Define an interval of 1 day, 15+ hours.
TimeSpan interval = new TimeSpan(1, 15, 42, 45, 750);
Console.WriteLine("Value of TimeSpan: {0}", interval);
Console.WriteLine("{0:N5} minutes, as follows:", interval.TotalMinutes);
Beware that there is a distinct difference between interval.Minutes and interval.TotalMinutes!
http://msdn.microsoft.com/en-us/library/system.timespan.totalminutes.aspx
Thus:
// my duration
int duration = Time.TotalMinutes;
// now insert this into the database
精彩评论