locked
Entity_Created Method (Both Desktop and HTML Client) RRS feed

  • Question

  • Hi everyone,

    So I'm adding some HTML pages to an existing Silverlight client. All is going well. However on one of the entities I have a "WeekEnding" property which as you may guess is the next Sunday from today. 

    I added the following code to the Entity_Created method:

    Dim Sunday As Date = Now.AddDays(7 - Convert.ToDouble(Now.DayOfWeek))
    WeekEnding = Sunday

    In the desktop client, when the user creates a new record the WeekEnding property is correctly populated with the date of the next Sunday as requested. The HTML client however, doesn't. The only way I can get the HTML client to follow suit is to click "HTMLClient" on the entity designer, go to it's created method and add the equivalent JavaScript code there.

    It seems strange to have to duplicate this code. Am I missing something?

    Thanks,

    Paul.

    Wednesday, November 20, 2013 11:49 PM

Answers

  • It seems strange to have to duplicate this code. Am I missing something.

    The Created method for entity run on the tier in which the entity is created. Since the Silverlight client uses VB/C# and the HTML client uses JavaScript, you should expect that the Created method in the Silverlight client is in VB/C# and the Created method in the HTML client is in JavaScript. Thus, you cannot write code once and use it in both clients.

    Justin Anderson, LightSwitch Development Team

    • Marked as answer by Paul Pitchford Thursday, November 21, 2013 10:32 AM
    Thursday, November 21, 2013 5:37 AM
    Moderator

All replies

  • It seems strange to have to duplicate this code. Am I missing something.

    The Created method for entity run on the tier in which the entity is created. Since the Silverlight client uses VB/C# and the HTML client uses JavaScript, you should expect that the Created method in the Silverlight client is in VB/C# and the Created method in the HTML client is in JavaScript. Thus, you cannot write code once and use it in both clients.

    Justin Anderson, LightSwitch Development Team

    • Marked as answer by Paul Pitchford Thursday, November 21, 2013 10:32 AM
    Thursday, November 21, 2013 5:37 AM
    Moderator
  • I suppose now you put it simple like that, I was sort of answering my own question. I'm so used to the Lightswitch trickery, I think the late night had me thinking it could work miracles too! :)

    Paul.

    Thursday, November 21, 2013 10:32 AM