2

I have sql database. In sql the column type is datetime nullable but in c# entities are defined as only datetime.

If the dateTime is null the response as xml format gives no problem but response as json format gives problem. If I change datetimes into datetime? response as json format works but it effects other entities in bad way.

How can I solve this problem? Thank you.

user3309441
  • 107
  • 11
  • In sql database, datetime nullable you mean allow null in datetime column? – Faizan Mubasher Mar 25 '14 at 07:57
  • Yes, it is allowed to be null. – user3309441 Mar 25 '14 at 07:59
  • 1
    How do we know what your other entities are and how are they affected by nullable `datetime` ? – Shaharyar Mar 25 '14 at 08:00
  • There is a lot of class and a lot of controls. So I can't write them here. In xml I see the datetime 0001-01-01T00:00:00, when it is null. But in json it gives error. It is my problem.There has to be something about DateTime for [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] – user3309441 Mar 25 '14 at 08:08
  • http://stackoverflow.com/questions/21960682/bad-request-when-making-a-call-to-a-rest-wcf-webservice/21966508#21966508 – Faizan Mubasher Mar 25 '14 at 08:59

1 Answers1

1

I think the problem is that the json serializer sends the date as 0001-01-01T00:00:00 UTC which can create problems when you deserialize it from a machine in a timezone ahead of UTC.

Try the solution in this thread and see if its helps: Why can DateTime.MinValue not be serialized in timezones ahead of UTC?

Community
  • 1
  • 1
mh__
  • 356
  • 2
  • 10