Bug 49004 - Mono and storing Timespan in sql server
Summary: Mono and storing Timespan in sql server
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data ()
Version: 4.8.0 (C9)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2016-12-05 12:16 UTC by Simeon
Modified: 2018-02-22 22:20 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Simeon 2016-12-05 12:16:56 UTC
I am trying to run my .Net MVC project on Mac OS X. I am trying to store a model with Timespan property in sql server 2008 database.But I am keep getting an error, when code is trying to store a value in timespan property.

"The parameter data type of System.TimeSpan is invalid."

I ran same project in windows ,connecting to same sql server and it works just fine.

Trying to debug the issue, I created a simple MVC project via xamarim studio. It uses entity framework code first approach and has one class:

	public class User
		public User()
		public int Id { get; set; }
		public string Name { get; set; }
		public TimeSpan? TheTime { get; set; }

In the home controller, I am doing that:

	                var db = new SchoolContext();
			var user = new User();
			user.Name = "aaaa";
			//user.TheTime = new TimeSpan(1,2,3);

The code runs fine unless I am uncomment the line with with "user.TheTime".
Also, the code runs fine in windows. Usual operations with the timespan are OK.

Here is full error - http://pastebin.com/0Y3eC5Tc
Comment 1 Simeon 2016-12-05 13:13:01 UTC
I examined the source code of System.Data.SqlClient.SqlParameter. I can't see any mentioning of Timespan type.
So, I added [Column(TypeName = "time")] to the class  User.TheTime property, but code throws same error in InferSqlType method.
Comment 2 Marek Safar 2018-02-22 22:20:54 UTC
Mono 5.10 has significantly improved System.Data implementation which should resolve this issue. If you can still reproduce it please reopen the issue.