문제

For some reason the 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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top