"The value can't be evaluated into type Time.

So, I have a datetime column called [Starting Time] in an SQL Server Dynamics NAV (On-Prem) database. It appears to have a default value of '1753-01-01 00:00:00.000'. If a time is assigned to the field in Business Central the date part in the database advances one year (e.g.) '1754-01-01 15:07:27.007'
I've created an AL Extension in VS Code containing an API Page in which one of the fields defined is the aforementioned [Starting Time] (see below):
field(StartingTime; "Starting Time") { }
When I hover the mouse cursor over this field in VS Code it reports: '(field) "Starting Time": Time'
I've then downloaded the XML metadata from Dynamics NAV (see section below). Notice, it has defined the field as "Edm.String" ?
<Property Name=""StartingTime"" Type=""Edm.String"">
  <Annotation Term=""NAV.LabelId"" String=""StartingTime"" />
  <Annotation Term=""NAV.NavType"">
    <EnumMember>NAV.NavType/String</EnumMember>
  </Annotation>
</Property>
I've then create an OData connected service in a C# .NET Core 2.2 Web App in Visual Studio 2019.
See auto-generated code below:-
/// <summary>
/// There are no comments for Property StartingTime in the schema.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.6.0")]
public string StartingTime
{
    get
    {
        return this._StartingTime;
    }
    set
    {
        this.OnStartingTimeChanging(value);
        this._StartingTime = value;
        this.OnStartingTimeChanged();
    }
}
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.6.0")]
private string _StartingTime;
partial void OnStartingTimeChanging(string value);
partial void OnStartingTimeChanged();
I have a Razor View as below, which displays a nice TimePicker control:-
@Html.EditorFor(model => Model.ServiceHeader.StartingTime, new { htmlAttributes = new { @class = "form-control", @type = "time" } })
The value chosen is returned to the Controller (e.g.) "01:00".
I populate the relevant object's properties and call the functions below to update the database via the OData interface:-
_context.AttachTo("API_Service_Header", lobjSH, "*");
_context.UpdateObject(lobjSH);
await _context.SaveChangesAsync(SaveChangesOptions.None);
... And I get the following error:-
{"error":{"code":"Application_EvaluateException","message":"The value \"1754-01-01 01:00:00\" can't be evaluated into type Time."}}
By the way I've tried formatting the value as just a time (e.g.) "01:00" and I've tried formatting it as full date (e.g.) "1754-01-01 01:00:00" - Same error.
Any help would be greatly appreciated?
Related
Recommended