You are here:   Blog
Register   |  Login

May 6

Written by: Michael Washington
5/6/2011 5:19 AM  RssIcon

I was surprised when I was chosen to present at Visual Studio Live in Las Vegas early this year. I had sent in 3 proposed topics months before, and the one chosen was Advanced LightSwitch Programming. After being informed of my selection to speak at the conference, I sat down to create the presentation and ran into a huge problem. There is just too much to cover about advanced LightSwitch programming to cram into 75 minutes.

I really agonized over this, and re-wrote the presentation several times. In the end, I spent over 40 hours preparing and practicing the presentation. The only structure I was happy with, was coving LightSwitch programming using three concepts that I felt were important to successful LightSwitch programming.

These are presented in order of importance.

Concept #1 - LightSwitch requires you to only write the code that only you can write

Examples of the concept:

  • A calculated field that shows the course and the teacher for the enrollment
  • Validation to prevent an Enrollment from starting before the Section it belongs to starts
  • Pre-process query to only show a teacher their classes when taking attendance

What it means:

  • If there is no way for LightSwitch to figure this out it’s self, then yes you must write the code, but if it can (for example if the Order table is related to the Customer table, it will know the Orders for the Customer), then there is usually a non-code way for you to achieve the objective.

Let’s ignore the Concept:

  • You will become frustrated trying to write code to explicitly update the sample calculated value, when a user updates the enrollment to assign it to another Teacher.

How to obey the concept:

  • When you wire up a method you will be asked a question (for example, return a bool or return a result). “Just answer the question”
  • Yes you can go off and perhaps call a web service to query an external system for the students StateID number, but if you find yourself creating records and updating records when the question was “tell me what you want displayed for this field”, you are fighting the concept
  • Try this “thought process”
    • First look to see if I should click on a field in a table and write some code?
    • Next, look to see if I should click on the table and write some code?
    • Next, should I create a Query and write some code? (for example, only allow teachers to see students enrolled in their class) Can I use a PreProcess query?
    • Next, should I create an external data source that will help?
    • Only last, should I add a button to a screen and write some code.

 

Concept #2 - When creating a Silverlight Custom Control, you only create custom UI, LightSwitch still handles everything else

Examples of the concept:

  • Creating an School Attendance control that uses radio buttons to allow the user to take attendance (LightSwitch does not provide a mechanism for using radio buttons without making a Silverlight Custom Control).

What it means:

  • We are not dropping into our own custom Attendance Module. The code that will process the Attendance will still be written inside the LightSwitch framework according to the LightSwitch rules.

Let’s ignore the Concept:

  • You really can’t. LightSwitch enforces the MVVM design and then only allows you to insert a custom Silverlight control on the “V”

How to obey the concept:

  • If LightSwitch will allow you to do it, then you’re not doing anything wrong

 

Concept #3 - Even when you implement advanced code, stay within the Framework

Examples of the concept:

  • Creating an in-memory record so the Attendance form shows a record for each student enrolled that day

What it means:

  • Even though we are creating in-memory records, we still are only filling the normal collection the screen is bound to

Let’s ignore the Concept:

  • We could try to bypass the normal collection and manually bind to the controls on the LightSwitch screen

How to obey the concept:

  • Try to only do one thing when implementing custom code in a LightSwitch method.

Tags: Concepts
Categories:

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 

Microsoft Visual Studio is a registered trademark of Microsoft Corporation / LightSwitch is a registered trademark of Microsoft Corporation