开发者

Subsonic ignoring TimeSpan property

开发者 https://www.devze.com 2023-01-03 13:24 出处:网络
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 us

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号