New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert DateTime to DateTimeOffset without judging the Kind attribute of a DateTime #488

Closed
QingshuChen opened this Issue Aug 9, 2016 · 0 comments

Comments

Projects
None yet
3 participants
@QingshuChen
Contributor

QingshuChen commented Aug 9, 2016

The datatype of TIMESTAMP in MySql will be mapped to DateTime (the kind attribute is 'local') in EF. When accessing the data with a datatype TIMESTAMP in mysql through RESTier, it throw an error:
{
"error":{
"code":"","message":"An error has occurred.","innererror":{
"message":"The 'ObjectContent1' type failed to serialize the response body for content type 'application/json; odata.metadata=minimal'.","type":"System.InvalidOperationException","stacktrace":"","internalexception":{ "message":"The UTC Offset of the local dateTime parameter does not match the offset argument.\r\nParameter name: offset","type":"System.ArgumentException","stacktrace":" at System.DateTimeOffset..ctor(DateTime dateTime, TimeSpan offset)\r\n at Microsoft.Restier.Publishers.OData.Formatter.RestierPrimitiveSerializer.CreateODataPrimitiveValue(Object graph, IEdmPrimitiveTypeReference primitiveType, ODataSerializerContext writeContext)\r\n at System.Web.OData.Formatter.Serialization.ODataPrimitiveSerializer.CreateODataValue(Object graph, IEdmTypeReference expectedType, ODataSerializerContext writeContext)\r\n at System.Web.OData.Formatter.Serialization.ODataEdmTypeSerializer.CreateProperty(Object graph, IEdmTypeReference expectedType, String elementName, ODataSerializerContext writeContext)\r\n at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateStructuralProperty(IEdmStructuralProperty structuralProperty, EntityInstanceContext entityInstanceContext)\r\n at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateStructuralPropertyBag(IEnumerable1 structuralProperties, EntityInstanceContext entityInstanceContext)\r\n at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.CreateEntry(SelectExpandNode selectExpandNode, EntityInstanceContext entityInstanceContext)\r\n at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteEntry(Object graph, ODataWriter writer, ODataSerializerContext writeContext, IEdmTypeReference expectedType)\r\n at System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n at System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n at System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n at System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)\r\n at Microsoft.Restier.Publishers.OData.Formatter.RestierFeedSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)\r\n at System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.WebHost.HttpControllerHandler.d__1b.MoveNext()"
}
}
}
}

The reason for the error is that RESTier converts DateTime to DateTimeOffset without judging the Kind attribute of a DateTime at Microsoft.Restier.Publishers.OData.Formatter.RestierPrimitiveSerializer.CreateODataPrimitiveValue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment