locked
odata DateTimeOffset error RRS feed

  • Question

  • LightSwitch 2013 is the current environment. I've been slowing converting DateTime fields to DateTimeOffset fields. I've run into an issue with a field called ThirdPartyAsOf.

    The prior code in c# using odata read:

                itmItem2update.ThirdPartyAsOf = Date.UtcNow;
                context.UpdateObject(itmItem2update);
                context.SaveChanges();

    The code worked properly through oData

    I updated the field in Lightswitch 2013 to DateTimeOffset. The database in Azure is properly updated as well. I can update the field manually through a screen.

    The updated code reads as follows:

                itmItem2update.ThirdPartyAsOf = DateTimeOffset.UtcNow;
                context.UpdateObject(itmItem2update);
                context.SaveChanges();

    I can do a watch on itmItem2update.ThirdPartyAsOf and watch the value update from old value to new value.

    An error is generated on context.SaveChanges();

    The short version is "Can't cast to unsupported type 'DateTimeOffset'.

    The long error is:

    System.NotSupportedException was unhandled by user code

      HResult=-2146233067

      Message=Can't cast to unsupported type 'DateTimeOffset'

      Source=System.Data.Services.Client

      StackTrace:

           at System.Data.Services.Client.ClientConvert.GetEdmType(Type propertyType)

           at System.Data.Services.Client.DataServiceContext.WriteContentProperty(XmlWriter writer, String namespaceName, ClientProperty property, Object propertyValue)

           at System.Data.Services.Client.DataServiceContext.WriteContentProperties(XmlWriter writer, ClientType type, Object resource, EpmSourcePathSegment currentSegment, Boolean& propertiesWritten)

           at System.Data.Services.Client.DataServiceContext.CreateRequestData(EntityDescriptor box, Boolean newline)

           at System.Data.Services.Client.DataServiceContext.SaveResult.CreateChangeData(Int32 index, Boolean newline)

           at System.Data.Services.Client.DataServiceContext.SaveResult.BeginNextChange(Boolean replaceOnUpdate)

           at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)

           at System.Data.Services.Client.DataServiceContext.SaveChanges()

           at ScriptMain.Input0_ProcessInputRow(Input0Buffer Row) in c:\Users\9eVKeCAKa6\AppData\Local\Temp\2\Vsta\fb207c9b3b394cbaa854c74126e0028a\main.cs:line 216

           at UserComponent.Input0_ProcessInput(Input0Buffer Buffer) in c:\Users\9eVKeCAKa6\AppData\Local\Temp\2\Vsta\fb207c9b3b394cbaa854c74126e0028a\ComponentWrapper.cs:line 36

           at UserComponent.ProcessInput(Int32 InputID, String InputName, PipelineBuffer Buffer, OutputNameMap OutputMap) in c:\Users\9eVKeCAKa6\AppData\Local\Temp\2\Vsta\fb207c9b3b394cbaa854c74126e0028a\ComponentWrapper.cs:line 27

           at Microsoft.SqlServer.Dts.Pipeline.ScriptComponent.ProcessInput(Int32 InputID, PipelineBuffer buffer)

           at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer)

      InnerException:

    I updated the service reference for the oData url which did not work. Next I deleted the service reference and then recreated - this did not work.

    Any ideas on how to debug?


    Thank you, Bill

    Wednesday, September 10, 2014 1:01 AM

All replies

  • *** bump ***

    Has anyone successfully written through oData to a LightSwitch DateTimeOffset field?


    Thank you, Bill

    Monday, September 15, 2014 8:40 PM
  • Hi Bill,

    In LightSwitch, there are 3 categories of use for the DateTimeOffset data type when building apps:

    •Client Values 

    Values set from the client, user entered, or set in javascript  screen.GlobalTime.ClientValue = new Date();

    •Mid-Tier Values

    Set through application logic, within the LightSwitch server pipeline  partial void GlobalTimes_Inserting(GlobalTime entity){

     entity.MidTierValue = DateTimeOffset.Now;

     }

    •Created/Modified Properties

    LightSwitch and Cloud Business Apps in Visual Studio 2013 now support stamping entity rows with Created/Modified properties. These values are set in the mid-tier.

    This will be helpful for you to troubleshoot. Further information:

    Announcing LightSwitch in Visual Studio 2013 Release Candidate!

    Global Time (Steve Lasker) 

    Please let me know if there is anything that I can do to help.

    Best regards,

    Angie 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 17, 2014 8:56 AM
  • Angie,

    Thank you for the information.

    I am actually writing via odata which I guess is closest to the middle tier method with entity.MidTierValue = DateTimeOffset.Now;

    That said, the error still occurs.

    Would you have any code examples of writing to DateTimeOffset via odata?

    Bill


    Thank you, Bill

    Wednesday, September 17, 2014 1:37 PM