locked
Lightswitch ViewModel Limitation RRS feed

  • Question

  • I am studying Lightswitch few weeks now and in a number of occasions I came upon a common requirement. I want inside my ViewModel (screen designer, left side) to create an entity that has nothing to do with my conceptual model, actually it is not conceptual the way it is implemented in LS but the actual tables footprint, according to my opinion. This is a viewmodel's responsibility to allow me to create entities according to my UI flow that have nothing to do with my conceptual model or tables structure.

    Am I missing something here? Am I the only one having this need? The only way I can see this to be doable is by using SL views or custom controls in LS but I wonder what waits me in the next corner.

    I don't want this entity to be editable but for presentation purposes only.

    Thank you...

    Thursday, December 27, 2012 3:34 PM

Answers

  • I agree Yann, with this way I can have what I wanted, but I hoped LS could cover that common limitation. After all according to MVVM pattern in ViewModel you can transform your data as you like before presenting them in the UI and that is why you have that middle tier.You have the View, the ViewModel and the Model. In LS I get the feeling that you have the View, the Model and the ViewModel is there just for binding. No data tranformation... If we just could create in the View Model a custom class, that would do for most of my scenarios.

    Perhaps is would help to understand why LightSwitch is the way it is if you consider that unlike "pure" MVVM, LightSwitch provides a extra things like:

    • Change tracking
    • Validation

    These things allow for rapid application development. Imagine if LightSwitch didn't have it. Make a bunch of changes on the screen and you would have to handle all validation and data persistent issues manually! :)

    When you create a WCF RIA Service you are required to provide the minimum that LightSwitch needs for it's style of MVVM.

    It really is not a lot and you will want to give it a try before deciding that it is insufficient for your needs (it takes me about 2 minutes to create a new WCF RIA service when I need one).

    What is nice is that you can make a pure POCO WCF RIA Service and you STILL get change tracking! :)

    I have created many MVVM applications the manual way and I would never go back because of the change tracking feature alone.


    The Visual Studio LightSwitch Marketplace

    http://LightSwitchHelpWebsite.com

    • Edited by ADefwebserver Tuesday, January 1, 2013 4:43 PM
    • Marked as answer by Angie Xu Tuesday, January 8, 2013 10:12 AM
    Tuesday, January 1, 2013 4:42 PM
  • You can create a custom RIA Service for your display entity (just make sure you do it the LightSwitch way, not the way you would in some other technology). RIA Services in LightSwitch are VERY easy!

    The basic procedure is described in this article:

    Creating a Simple LightSwitch RIA Service (using POCO)


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
     
    By doing this you'll help others to find answers faster.

    • Marked as answer by Angie Xu Tuesday, January 8, 2013 10:12 AM
    Saturday, December 29, 2012 6:35 AM
    Moderator

All replies

  • Don't understand quite well.

    Imagine you defined, e.g. Customers and Orders as entities in your domain model (so via the designer).

    Do I understand correctly, that you want now to add e.g.  a product entity to one of your screens without having it defined in the domain model?

    If so, that won't work.


    paul van bladel


    Friday, December 28, 2012 1:15 PM
  • You can create a custom RIA Service for your display entity (just make sure you do it the LightSwitch way, not the way you would in some other technology). RIA Services in LightSwitch are VERY easy!

    The basic procedure is described in this article:

    Creating a Simple LightSwitch RIA Service (using POCO)


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
     
    By doing this you'll help others to find answers faster.

    • Marked as answer by Angie Xu Tuesday, January 8, 2013 10:12 AM
    Saturday, December 29, 2012 6:35 AM
    Moderator
  • Hi Paul.

    Based on your example consider this.

    I would like to have a screen that shows me in a grid the client name, the product name and how many times a client ordered that product and maybe the total quantities. Now this is a simplified example but I hope you can get the picture.

    If I was working with WPF or SL I would create my entities Customers, Orders and Products using POCO or EF and in the ViewModel, after querying database I would create that custom class collection, fill it with values and bind my grid to it.

    Lightswitch allows you in the ViewModel to create only properties, methods and entities that you already designed or imported from a service or DB. It doesn't have the option to create a custom class. 

    Sunday, December 30, 2012 10:16 PM
  • I agree Yann, with this way I can have what I wanted, but I hoped LS could cover that common limitation. After all according to MVVM pattern in ViewModel you can transform your data as you like before presenting them in the UI and that is why you have that middle tier.You have the View, the ViewModel and the Model. In LS I get the feeling that you have the View, the Model and the ViewModel is there just for binding. No data tranformation... If we just could create in the View Model a custom class, that would do for most of my scenarios.

    Sunday, December 30, 2012 10:21 PM
  • It's not a scenario that LightSwitch was architected to cover. But the "out" is that you can create whatever custom entities you need with a RIA Service.

    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
     
    By doing this you'll help others to find answers faster.

    Monday, December 31, 2012 7:08 AM
    Moderator
  • I agree Yann, with this way I can have what I wanted, but I hoped LS could cover that common limitation. After all according to MVVM pattern in ViewModel you can transform your data as you like before presenting them in the UI and that is why you have that middle tier.You have the View, the ViewModel and the Model. In LS I get the feeling that you have the View, the Model and the ViewModel is there just for binding. No data tranformation... If we just could create in the View Model a custom class, that would do for most of my scenarios.

    Perhaps is would help to understand why LightSwitch is the way it is if you consider that unlike "pure" MVVM, LightSwitch provides a extra things like:

    • Change tracking
    • Validation

    These things allow for rapid application development. Imagine if LightSwitch didn't have it. Make a bunch of changes on the screen and you would have to handle all validation and data persistent issues manually! :)

    When you create a WCF RIA Service you are required to provide the minimum that LightSwitch needs for it's style of MVVM.

    It really is not a lot and you will want to give it a try before deciding that it is insufficient for your needs (it takes me about 2 minutes to create a new WCF RIA service when I need one).

    What is nice is that you can make a pure POCO WCF RIA Service and you STILL get change tracking! :)

    I have created many MVVM applications the manual way and I would never go back because of the change tracking feature alone.


    The Visual Studio LightSwitch Marketplace

    http://LightSwitchHelpWebsite.com

    • Edited by ADefwebserver Tuesday, January 1, 2013 4:43 PM
    • Marked as answer by Angie Xu Tuesday, January 8, 2013 10:12 AM
    Tuesday, January 1, 2013 4:42 PM