1

I have my class with a data member Datetime StartDate.

This value is filled by the database and can be empty. In this case, I do this command :

StartDate = new DateTime ()

Besides, this property is sent by a WCF service. But, when the StartDate is empty (so equal to 01/01/0001) my client loose the connection with the service.

Should I use another type for WCF (datetimeoffset) ? Or how can I use the datetime ?

Thanks !

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ahikaz
  • 61
  • 2
  • 7

1 Answers1

3

Consider using a nullable DateTime in your contract:

[DataMember]
public Nullable<DateTime> StartDate {get;set;}

or

[DataMember]
public DateTime? StartDate {get;set;}
Paul Fleming
  • 24,238
  • 8
  • 76
  • 113
  • OK, but why the MinValue of DateTime don't work with WCF ? :S – ahikaz Jul 17 '12 at 14:07
  • I'm not sure for certain but this may help: http://stackoverflow.com/questions/4025851/why-can-datetime-minvalue-not-be-serialized-in-timezones-ahead-of-utc – Paul Fleming Jul 17 '12 at 14:09
  • Also, if you're persisting to a MS SQL Server database, Sql DateTime has a min value of January 1, 1753. http://msdn.microsoft.com/en-us/library/system.data.sqltypes.sqldatetime.minvalue.aspx – Paul Fleming Jul 17 '12 at 14:11
  • Thanks for the links, i added ToUniversalTime to my command and it works now :) : it was a serialization problem. – ahikaz Jul 17 '12 at 14:39