söndag 3 oktober 2010

Lightswitch - adding relations

So, there's that old LightSwitch application of mine. Not that fancy, when do you ever need to have a frontend for an application containing only one single table?

To make the application more interesting, let's start with adding a new table. Right click the "Data source" in the Solution Explorer and choose "Add table". Give the table a good name, like "Project" and add some relevant columns like before. Also, add a column called "Category" (or whatever you prefer) and make it Int16. This one will be our "choice list". To create it, choose "Choice List" in the properties view.


A choicelist consists of a predefined value (an int in this example) and another value that will be displayed on the screen in a combobox.


Relations
When your table is ready - save all the files and start thinking about the relationship between the two tables. In my example, an administrator will administrate many projects, but to keep things simple, every project will only have one responsible administrator.
Start by clicking the "Relations" button in the top toolbar.



Design your relationship as you want it. Note the describing text at the bottom of the window, this one helps you understand the desired behaviour.


Now, after you saved your extremely intelligent relationship you will notice a new column in the "Project" table, namely "Administrator". (That is, if you created a solution like mine. If not, I won't have a clue to whatever the new column is called in your table..)
Now, we will need a better screen for displaying our application. Right click the "Screens" folder and add a new "List  and Detail" screen. Give it a good name, set the "Screen Data" to Projects and let it free!


If everything is well, you should be able to add projects with pre-defined categories and Administrators from the "Administrator" table. (Make sure to put some guys (or girls) in there).

And that's  it for today. The application is not very advanced, but is definietly closer to solve a real world scenario. Next time, I'll add some more logic into the soup!!

Inga kommentarer:

Skicka en kommentar