Monday, September 6, 2010

LightSwitch Concurrency

 

I was curious how LightSwitch dealt with database concurrency, so I setup a little test to find out. I started with the sample application I have been working on in my previous posts. First I published the application then ran the setup and finally started two instances of the application. Next I added a new record, and then opened it for editing in both instances. In one instance I made a change to the Address field and saved the record. In the second instance I made a change to Start Date field and clicked save. When I did this LightSwitch detected the concurrency violation and displayed the following screen:

clip_image002

Here for each conflicting field you receive a drop down menu where you can select between the value on the server and the one from your instance.

Saturday, September 4, 2010

LightSwitch Query and Details Screens


In my first posting on LightSwitch I showed how to setup a screen to create a new record. This isn't very useful without a way to view and edit records. In this posting I will show how to setup a search and details screen.

I am going to start with the same Employee table I created in the first post:

clip_image002

Next I created a new Search screen for Employees. When you run the app you will get the new search screen:

clip_image004

On this screen you can browse records, search from them, export them to Excel and click the Employee name to edit the record. This brings up a couple questions. First, where does the edit screen come from? It's not the same as the Create screen we started with. Turns out LightSwitch dynamically creates the edit screen when you view the record. You can easily override this by creating a new Details Screen like this:

clip_image006

If you keep the Use as Default Details Screen option checked it will become the details/edit screen that opens when you click on a record.

The next question is how do you change the field that you click to view a record? This is not entirely intuitive; you need to make the change in the table view. Select the table, and then at the bottom of the properties window set the Summary Property to the one that you want to be clickable. You can also change the Display Name which will become the name at the top of the column. In this example I am using the Id as the Summary Property:

clip_image008

To finish this you need to go back to the editor for the SearchEmployee screen and add the FirstName into the field list:

clip_image010

Now when you run the application the Id will be clickable to take you to the detail/edit screen.

clip_image012