HTML Client entity augmentation vs SL Client RRS feed

  • Question

  • Hi all,

    On the server we can augment our entities with properties and methods to be used at run-time, since they are partial classes. Since these are shared in a Silverlight application, we can refer to, or call these properties/methods at any time.

    For example, I could decorate my Customer class thus:

    // Property

    public bool CanDelete { get { return (this.Details.EntityState == EntityState.Unchanged); } }

    // Method

           private void AddAddress()
                if (this.AddressesFor.Count() == 1)
                    this.AddressesFor.Where(o => o.Details.EntityState == EntityState.Added).FirstOrDefault().IsDefaultAddress;

    In this instance and particularly from the point of view of an existing project, this stuff is referred to/called on the client side.

    Although some 'decorations' may well still be valid on the server c#-based instance (if they are instantiated from that tier obviously!), my question is that since they would definitely be wanted on the (HTML) client-side, how does one 'decorate' the JS-based entity with these properties/methods on the client?

    In equivalent terms, I guess what I'm trying to say that the JS entity file is not partial so how would what I'm asking be achieved?


    Ian Mac

    Friday, June 27, 2014 12:49 PM

All replies

  • See:

    HUY Volume III– Popups, Dirty Visual Collections, and Using Prototypes To Calculate Child Collections 

    // Calculated field to count Available OrderDetails
    myapp.Order.prototype.getAvailable = function () {
        return this.OrderDetails.sum(function (item) {
            return item.ItemAvailable == true;

    Unleash the Power - Get the LightSwitch HTML Client book


    Saturday, June 28, 2014 12:08 PM
  • Hi Michael,

    Many thanks for that.

    I have been experimenting also with inheritance on the HTML Client, with little or no success to date unfortunately! OK now I know more of prototypes on 'classes', but what I'd like to do is minimise code all round.

    The common entity properties and/or methods I want any entity instance to inherit are only needed on the client. For example a 'canDelete' method (it doesn't matter what the methods/properties actually are, I'm more after the principle).

    In C# obviously we can use Interfaces and base classes and I'm guessing something like this can be achieved in JavaScript in a 'pseudo' manner.

    So basically (on the client), I'd like my Js entities to 'inherit' from a 'base class'.

    Given my unsuccessful attempts so far (not a Js geek yet!), I wonder if you could kindly point me in the right direction? I would have though that this would be quite useful. Either that or I'm 'barking up the wrong tree'!



    Ian Mac

    Sunday, July 6, 2014 1:59 PM
  • My understanding is that LightSwitch is creating the JavaScript, that comprises the entities that you see, based on the data layer that that you define using the LightSwitch entity designer. This article goes into that in detail: A Tour of the LightSwitch HTML Client APIs (Elizabeth Maher).

    It appears that you want to insert code in that process? The msls.js file is the core part of that process. I guess it could be modified but I would not recommend it.

    There is a Can Delete process by writing code in the Edit CanExecute Code for a Delete method:

    Unleash the Power - Get the LightSwitch HTML Client book


    Sunday, July 6, 2014 2:52 PM