<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Beth Massi - Sharing the goodness that is VB</title><subtitle type="html">Community champion for business application and Visual Basic developers</subtitle><id>http://blogs.msdn.com/b/bethmassi/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/b/bethmassi/atom.aspx" /><generator uri="http://telligent.com" version="5.6.583.20496">Telligent Community 5.6.583.20496 (Build: 5.6.583.20496)</generator><updated>2011-10-06T13:58:22Z</updated><entry><title>LightSwitch Screen Tips: Scrollbars and Splitters</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2012/02/09/lightswitch-screen-tips-scrollbars-and-splitters.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2012/02/09/lightswitch-screen-tips-scrollbars-and-splitters.aspx</id><published>2012-02-09T15:08:00Z</published><updated>2012-02-09T15:08:00Z</updated><content type="html">&lt;p&gt;Often times in business applications we have a lot of information to present on a screen, and depending on the user’s screen resolution that information may scroll off the page. &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;Visual Studio LightSwitch&lt;/a&gt;’s screen templates are set to automatically apply a vertical scrollbar to screens when this happens, however, sometimes we rather allow the user to resize sections of the screen how they see fit. It’s common in screen design to use splitter controls to do this. Splitters are a useful UI feature where the width or height of a control on the screen can be modified to show more or less information. In this post I’ll show you how you can enable splitter controls to appear in LightSwitch as well as control how scrollbars behave. &lt;/p&gt;  &lt;h3&gt;Create Your Screen&lt;/h3&gt;  &lt;p&gt;First &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff949859" target="_blank"&gt;create a screen&lt;/a&gt; with all the information you want to display. For this example I will use the ContactDetails screens we created in the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/26/beginning-lightswitch-address-book-sample.aspx" target="_blank"&gt;Address Book Sample&lt;/a&gt;. In this example, Contacts have many Addresses, PhoneNumbers and EmailAddresses. By default, LightSwitch will place the Contact fields at the top of the screen with a Tab Control of three DataGrids representing the children. &lt;/p&gt;  &lt;p&gt;Here is what the screen looks like:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3782.image_5F00_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8407.image_5F00_thumb_5F00_2.png" width="618" height="492" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;And here is the content tree for the screen:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2627.image_5F00_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5857.image_5F00_thumb_5F00_7.png" width="331" height="675" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Scrollbars in LightSwitch&lt;/h3&gt;  &lt;p&gt;Imagine that over time our contacts get more and more email addresses, phone numbers, and/or addresses. If the user’s screen resolution is low (or the size of the application shell is not maximized) then LightSwitch will place a vertical scrollbar on the screen by default (I added the green box for clarity ;-))&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3617.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6837.image_5F00_thumb_5F00_3.png" width="619" height="418" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This is controlled by selecting the topmost Rows Layout and under the Appearance properties you will see “Vertical Scroll Enabled” checked. Notice there is also a “Horizontal Scroll Enabled” property you can use to enable horizontal scrollbars when needed. All group controls in LightSwitch have these properties (i.e. Rows Layout, Columns Layout, Table Layout)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3782.image_5F00_18.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3617.image_5F00_thumb_5F00_8.png" width="565" height="339" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Leaving this checked however, means that the user cannot see all the email addresses and the First &amp;amp; Last name fields at the same time. There are a couple things we can do here. One is we can disable vertical scroll of the screen. Once we do that LightSwitch will automatically place the scrollbar into the grid itself instead.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6837.image_5F00_20.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2625.image_5F00_thumb_5F00_9.png" width="605" height="389" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;But what if we aren’t using a DataGrid (or list control) below the list of fields? Or what if we want the user to choose how many rows they need to view at a time? In those cases, we can allow the user to resize the panels of information using a splitter. &lt;/p&gt;  &lt;h3&gt;Adding a Horizontal Splitter&lt;/h3&gt;      &lt;p&gt;In order to provide this functionality, we can place a splitter between the list of fields at the top and the tab control below. While the application is running in debug mode, click the “Design Screen” at the top-right of the shell to open &lt;a href="http://msdn.microsoft.com/en-us/library/ff852030.aspx" target="_blank"&gt;Customization Mode&lt;/a&gt;. Select the nested Rows Layout control for Contact and under the sizing properties you will see a check box “Is Row Resizable”.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3617.image_5F00_22.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3288.image_5F00_thumb_5F00_10.png" width="685" height="441" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Check that and then click Save to save your changes. You will now see a splitter control that you can use to resize the top and bottom panels. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4452.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4278.image_5F00_thumb_5F00_4.png" width="669" height="430" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In this case you probably also want to set a minimum and maximum height of this Rows Layout panel so that the user doesn’t use the splitter to wipe the grid completely off the screen. Right now if you take and drag the splitter off the screen, the grid will completely disappear. In order to stop this, you can set the MinHeight and MaxHeight properties. You can enable a scroll bar to appear in the top panel when needed by checking “Vertical Scroll Enabled” as well.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5342.image_5F00_26.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7506.image_5F00_thumb_5F00_12.png" width="561" height="404" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Adding Vertical Splitters&lt;/h3&gt;  &lt;p&gt;You can also add vertical splitters in a similar way. Instead of displaying DataGrids in separate tabs, say we want to display them side-by-side. Open customization mode again and change the Tabs Layout to a Columns Layout.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3617.image_5F00_28.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3276.image_5F00_thumb_5F00_13.png" width="283" height="379" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then select each DataGrid and in the Sizing properties, check “Is Column Resizable”. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3386.image_5F00_30.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8081.image_5F00_thumb_5F00_14.png" width="749" height="497" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now you can resize all of the columns containing the DataGrids. The DataGrids will automatically put a horizontal scrollbar at the bottom so users can see all the fields as necessary.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6835.image_5F00_32.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6332.image_5F00_thumb_5F00_15.png" width="694" height="460" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Another Example &lt;/h3&gt;  &lt;p&gt;Splitters and scrollbars really start helping you out when you have sections of information and/or commands that you want to allow the user to resize. Here I modified the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/05/25/contoso-construction-lightswitch-advanced-development-sample.aspx" target="_blank"&gt;Contoso Construction example&lt;/a&gt; to allow resizing of the tab control of commands on the left and the information on the right. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7418.image_5F00_34.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7870.image_5F00_thumb_5F00_16.png" width="675" height="527" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Wrap Up&lt;/h3&gt;  &lt;p&gt;There are a lot of things you can do with the LightSwitch Screen designer in order to provide completely customized layouts. Controlling scrollbars and adding splitters is just another way you can achieve what you want. For more tips and tricks on customizing screens see:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/06/23/tips-and-tricks-for-using-the-screen-designer.aspx" target="_blank"&gt;Tips and Tricks for Using the Screen Designer&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/06/i-command-you-lightswitch-screen-commands-tips-amp-tricks.aspx"&gt;LightSwitch Screen Commands Tips &amp;amp; Tricks&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/17/lightswitch-tips-amp-tricks-on-dnrtv.aspx"&gt;LightSwitch &lt;em&gt;Tips&lt;/em&gt; &amp;amp; &lt;em&gt;Tricks&lt;/em&gt; on dnrTV&lt;/a&gt;&amp;#160;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10265663" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Screens" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Screens/" /></entry><entry><title>LightSwitch Community &amp; Content Rollup–January 2012</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2012/02/02/lightswitch-community-amp-content-rollup-january-2012.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2012/02/02/lightswitch-community-amp-content-rollup-january-2012.aspx</id><published>2012-02-02T15:30:00Z</published><updated>2012-02-02T15:30:00Z</updated><content type="html">&lt;p&gt;Last Fall I started posting a rollup of interesting community happenings, content, samples and extensions popping up around &lt;a href="http://msdn.com/lightswitch"&gt;Visual Studio LightSwitch&lt;/a&gt;. If you missed those rollups you can check them out here: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/09/29/lightswitch-community-amp-content-rollup-september.aspx"&gt;LightSwitch Community &amp;amp; Content Rollup–September 2011&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/31/lightswitch-community-amp-content-rollup-october-2011.aspx"&gt;LightSwitch Community &amp;amp; Content Rollup–October 2011&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/11/30/lightswitch-community-amp-content-rollup-november-2011.aspx"&gt;LightSwitch Community &amp;amp; Content Rollup–November 2011&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/05/lightswitch-community-amp-content-rollup-december-2011.aspx"&gt;LightSwitch Community &amp;amp; Content Rollup–December 2011&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Looks like folks took a few well-deserved days to ramp back into the groove after the holidays (including myself). But there were still a lot of awesome things around LightSwitch this month, especially the number of submissions &lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx" target="_blank"&gt;The Code Project&lt;/a&gt; had in the LightSwitch Star Contest. A lot of really interesting applications and some great case studies for LightSwitch as well as some for Azure. Check them out…&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;“LightSwitch Star” Contest&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=232292"&gt;&lt;img style="margin: 0px 10px 0px 0px" border="0" alt="“LightSwitch Star” Contest on CodeProject" align="left" src="http://i.msdn.microsoft.com/ff796201.LightSwitchStarContest(en-us,MSDN.10).jpg" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In November The Code Project launched the &lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;“LightSwitch Star” contest&lt;/a&gt;. They’re looking for apps that show off the most productivity in a business as well as apps that use extensions in a unique, innovative way. Prizes are given away each month. Soon they will announce the January winners as well as the two grand prize winners of an &lt;b&gt;&lt;a href="http://www.amazon.com/U31SD-DH31-13-3-Inch-Light-Laptop-Black/dp/B005PAIQG0/ref=dp_ob_title_ce"&gt;ASUS U31SD-DH31 Laptop&lt;/a&gt;&lt;/b&gt;! &lt;/p&gt;  &lt;p&gt;Check out all the submission we had in January and make sure to log onto Code Project and vote &lt;a href="http://www.codeproject.com/KB/LightSwitch/#LightSwitch+Star+Contest" target="_blank"&gt;for your favorites&lt;/a&gt;. Here’s a breakdown of the 13 apps that were submitted in January (see all &lt;a href="http://www.codeproject.com/KB/LightSwitch/#LightSwitch+Star+Contest"&gt;34 apps that have been submitted here&lt;/a&gt;). There are some very creative “business apps” here – like a campaign manager for Dungeons &amp;amp; Dragons!    &lt;br /&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.youtube.com/watch?v=G3xQ4bdL6GE&amp;amp;list=FLgFBc_I8vOTYjXOj0uyQTJA&amp;amp;index=5&amp;amp;feature=plpp_video"&gt;Profiling-Pro (video)&lt;/a&gt; – Project profiler that helps make sure your software projects are done on time&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/314201/Luminous-Commands"&gt;Luminous Commands For LightSwitch&lt;/a&gt; - Luminous Commands provides two pieces of functionality that was missing from LS RTM but wanted by many users&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/314208/Access-Control-Manager"&gt;Access Control Manager&lt;/a&gt; - The Access Control Manager tracks user access to applications and other products (such as hardware, cellphones, etc.) by creating requests for access by the supervisor of the user&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/316162/Light-Enterprise-Solution"&gt;Light Enterprise Solution&lt;/a&gt; - An article about applications that is an enterprise system targeted for Small &amp;amp; Medium Enterprises in Malaysia and Singapore&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/316676/Lightswitch-Job-Hunter-Application"&gt;LightSwitch Job Hunter Application&lt;/a&gt; - Job application tracker for those out of work built using Visual Studio LightSwitch 2011.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.youtube.com/watch?v=ppOb5DHBR-4&amp;amp;list=FLgFBc_I8vOTYjXOj0uyQTJA&amp;amp;index=1&amp;amp;feature=plpp_video"&gt;Job Hunter LightSwitch Application (video)&lt;/a&gt; - This is a demo video of a free application that is intended to help job applicants. The application and source code are free to download&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.youtube.com/watch?v=fifFyOQuADU&amp;amp;list=FLgFBc_I8vOTYjXOj0uyQTJA&amp;amp;index=2&amp;amp;feature=plpp_video"&gt;Illuminous overview (video)&lt;/a&gt; - Illuminous is a comprehensive college management tool developed using Visual Studio LightSwitch.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/318840/Data-Centre-A-Product-Information-and-Promotion-Ma"&gt;Data Centre: A Product Information and Promotion Management System&lt;/a&gt; - A system for easily and effectively storing product information and managing promotions.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/317928/Visual-Studio-LightSwitch-Application-Database-Scr"&gt;Visual Studio LightSwitch Application Database Script Generator&lt;/a&gt; - A tool to generate Sql server DB script from the LightSwitch internal database&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/319456/MyBizz-Portal-The-smallest-LightSwitch-application" target="_blank"&gt;MyBizz Portal&lt;/a&gt; - The &amp;quot;smallest&amp;quot; LightSwitch application you have ever seen. A portal to other LightSwitch applications.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/321845/Client-Management-System" target="_blank"&gt;Client Management System&lt;/a&gt; - A complete CRM solution that manages the entire customer lifecycle.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://staging.codeproject.com/Articles/322680/BPO-Productivity-Tool" target="_blank"&gt;BPO Productivity Tool&lt;/a&gt; - This is is primarily built as a custom LightSwitch Shell Extension in which I embed PRISM to manage all LightSwitch and non-LightSwitch views. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/322658/Birthright-Campaign-Manager" target="_blank"&gt;Birthright Campaign Manager&lt;/a&gt; - Birthright Campaign Manager is an open source role playing computer aid for Birthright, a campaign setting for Dungeons &amp;amp; Dragons. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;There are a lot of really interesting real-world LightSwitch production applications that were submitted. Some departmental apps, a few personal apps, some enterprise apps as well as a couple start-up companies. There are also some great case studies here for Azure, in particular:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/318840/Data-Centre-A-Product-Information-and-Promotion-Ma"&gt;Data Centre: A Product Information and Promotion Management System&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/316162/Light-Enterprise-Solution"&gt;Light Enterprise Solution&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/Articles/302593/Orion"&gt;Orion - MiniCRM LightSwitch and Azure&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;    &lt;h3&gt;Developer Center Updates&lt;/h3&gt;  &lt;h5&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857"&gt;Learn Page Updates&lt;/a&gt;&lt;/h5&gt;  &lt;p&gt;In December I kicked off a &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/tags/beginning+lightswitch+series/"&gt;series aimed at beginner developers&lt;/a&gt; just getting started with LightSwitch and was featured in the &lt;a href="http://msdn.microsoft.com/en-us/hh708735"&gt;MSDN Flash Newsletter&lt;/a&gt;. In January we updated the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857"&gt;Learn page of the Developer Center&lt;/a&gt; to feature this series and it’s been getting some great traffic!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 12px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1777.image_5F00_3.png" width="477" height="418" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I also released the completed source code for the sample we build in the series: &lt;a href="http://code.msdn.microsoft.com/Begining-LightSwitch-508763ea"&gt;Beginning LightSwitch - Address Book Sample&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;How Do I Videos – Learning Made Easier&lt;/h5&gt;  &lt;p&gt;We also updated all the How Do I video pages to show the sequential list of videos so that you can easily get to the previous and next videos in the series. This makes it a lot easier to navigate through the over 20 videos in the correct order. Just click into &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff949856"&gt;any video page like this one&lt;/a&gt; and you will see the video navigator at the bottom of the page.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff949856"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4807.image_5F00_6.png" width="468" height="414" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Notable Content this Month&lt;/h3&gt;  &lt;p&gt;Here’s some more of the fun things the team and community released in January. &lt;/p&gt;  &lt;h6&gt;Extensions released in January (&lt;a href="http://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=SearchText&amp;amp;f%5B0%5D.Value=LightSwitch&amp;amp;sortBy=Date"&gt;see all 73 of them here!&lt;/a&gt;):&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/df61b7a8-f3dc-4e91-a544-76acbcc465e9"&gt;Extended Text Box Extension &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/6cb027ee-cd5f-47a6-ad63-c40a925891e3"&gt;Visual Studio LightSwitch application DB script generator &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The team also released a control extension sample that you can learn from. Check out the announcement on the team blog:&amp;#160; &lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2012/01/17/many-to-many-control-released.aspx"&gt;Many-to-Many Control Released!&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Build your own extensions by visiting the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh304488"&gt;LightSwitch Extensibility page&lt;/a&gt; on the &lt;a href="http://msdn.com/lightswitch"&gt;LightSwitch Developer Center&lt;/a&gt;. &lt;/p&gt;  &lt;h5&gt;Team Articles:&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/30/calling-web-services-to-validate-data-in-visual-studio-lightswitch.aspx"&gt;Calling Web Services to Validate Data in Visual Studio LightSwitch&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/26/beginning-lightswitch-address-book-sample.aspx"&gt;Beginning LightSwitch–Address Book Sample&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/20/using-different-edit-screens-based-on-record-types-table-inheritance.aspx"&gt;Using Different Edit Screens Based on Record Types (Table Inheritance)&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/12/creating-cascading-drop-down-lists-in-visual-studio-lightswitch.aspx"&gt;Creating Cascading Drop Down Lists in Visual Studio LightSwitch&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2012/01/12/drop-down-lists-tips-amp-tricks-beth-massi.aspx"&gt;Drop-down Lists Tips &amp;amp; Tricks &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;Community Articles:&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/90/List-Box-That-Can-Be-Ordered-By-The-End-User.aspx"&gt;List Box That Can Be Ordered By The End-User&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/92/Save-is-a-pain-in-the-As.aspx"&gt;Save (is a pain in the) As&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/93/Using-The-Sheel-Shah-Many-To-Many-Control.aspx"&gt;Using The Many-To-Many Control&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/94/Using-the-ComponentOne-Excel-for-Silverlight-Control-with-LightSwitch.aspx"&gt;Using the ComponentOne Excel for Silverlight Control with LightSwitch&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/95/Application-Logo.aspx"&gt;Application Logo&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/96/A-LightSwitch-Web-Installer-Wizard.aspx"&gt;A LightSwitch Web Installer Wizard&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/97/Creating-a-Visual-Studio-LightSwitch-Screen-Template.aspx"&gt;Creating a Visual Studio LightSwitch Screen Template&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/98/Creating-A-LightSwitch-Theme-Extension-using-Expression-Blend.aspx"&gt;Creating A LightSwitch Theme Extension using Expression Blend&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://janvanderhaegen.wordpress.com/2012/01/18/extensions-made-easy-usesmallimage-and-custom-ordering/"&gt;Extensions Made Easy: UseSmallImage and custom ordering.&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://janvanderhaegen.wordpress.com/2012/01/17/centric-rad-race-may-the-better-technology-win/"&gt;Centric RAD race: may the better technology win…&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://janvanderhaegen.wordpress.com/2012/01/10/lightswitch-achievements-chapter-one-introduction-the-idea/"&gt;LightSwitch Achievements: Chapter one (Introduction) – The idea&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://janvanderhaegen.wordpress.com/2012/01/08/extensions-made-easy-1-11-navigation-sample-explained/"&gt;Extensions made easy 1.11 : navigation sample explained&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://powerbala.com/2012/01/01/extending-lightswitch-textbox-walk-through/"&gt;Extending LightSwitch TextBox : Walk-Through&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchregularguy.wordpress.com/2012/01/27/resources-for-beginners/"&gt;Resources for Beginners&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchregularguy.wordpress.com/2012/01/29/an-easy-way-to-create-many-to-many-relationships/"&gt;An Easy Way to Create Many-to-Many Relationships&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;&lt;strong&gt;Presentations:&lt;/strong&gt;&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;a href="http://www.techdays.ca/contentlibrary/video/en/2011-lightswich-is-hot!-really-hot!!.aspx"&gt;LightSwitch is Hot! Really Hot!!&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.kunal-chowdhury.com/2012/01/presented-lightswitch-for-business.html"&gt;Presented “LightSwitch for Business Application Development” in Microsoft Monday&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;Samples (&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh204519"&gt;see all of them here&lt;/a&gt;):&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Extended-Text-Box-b8c7b911"&gt;Extended Text Box Extension - Source Code&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/NavigationDemo-having-some-f2629c9c"&gt;NavigationDemo: having some fun in LightSwitch with the EME navigation model&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Many-to-Many-Control-for-52cd8c6c"&gt;Many to Many Control for Visual Studio LightSwitch&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Begining-LightSwitch-508763ea"&gt;Beginning LightSwitch - Address Book Sample&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;LightSwitch Team Community Sites&lt;/h5&gt;  &lt;p&gt;&lt;a href="http://www.facebook.com/vslightswitch"&gt;&lt;img style="margin: 0px 6px 0px 0px" border="0" alt="" align="left" src="http://badge.facebook.com/badge/151211271561073.1904.953280091.png" width="137" height="84" /&gt;&lt;/a&gt; The &lt;a href="http://www.facebook.com/vslightswitch"&gt;Visual Studio LightSwitch Facebook Page&lt;/a&gt; has been increasing in activity thanks to you all. Become a fan! Have fun and interact with us on our wall. Check out the cool stories and resources. &lt;/p&gt;  &lt;p&gt;Also here are some other places you can find the LightSwitch team: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/category/vslightswitch"&gt;LightSwitch MSDN Forums&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.com/lightswitch"&gt;LightSwitch Developer Center&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/lightswitch"&gt;LightSwitch Team Blog&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://twitter.com/#!/VSLightSwitch"&gt;LightSwitch on Twitter&lt;/a&gt; (@VSLightSwitch, #VisualStudio #LightSwitch) &lt;/p&gt;  &lt;h6&gt;Join Us!&lt;/h6&gt;  &lt;p&gt;The community has been using the hash tag #LightSwitch on twitter when posting stuff so it’s easier for me to catch it (although this is a common English word so you may end up with a few weird ones ;-)). &lt;a href="http://twitter.com/#!/search/realtime/%23LightSwitch"&gt;Join the conversation!&lt;/a&gt; And if I missed anything please add a comment to the bottom of this post and let us know!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10263122" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Community" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Community/" /><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="Samples" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Samples/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Rollup" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Rollup/" /></entry><entry><title>Calling Web Services to Validate Data in Visual Studio LightSwitch</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/30/calling-web-services-to-validate-data-in-visual-studio-lightswitch.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2012/01/30/calling-web-services-to-validate-data-in-visual-studio-lightswitch.aspx</id><published>2012-01-30T14:15:00Z</published><updated>2012-01-30T14:15:00Z</updated><content type="html">&lt;p&gt;Very often in business applications we need to validate data through another service. I’m not talking about validating the format of data entered – this is very simple to do in LightSwitch -- I’m talking about validating the &lt;strong&gt;meaning &lt;/strong&gt;of the data. For instance, you may need to validate not just the format of an email address (which LightSwitch handles automatically for you) but you also want to verify that the email address is real. Another common example is physical Address validation in order to make sure that a postal address is real before you send packages to it. &lt;/p&gt;  &lt;p&gt;In this post I’m going to show you how you can call web services when validating LightSwitch data. I’m going to use the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/26/beginning-lightswitch-address-book-sample.aspx" target="_blank"&gt;Address Book sample&lt;/a&gt; and implement an Address validator that calls a service to verify the data. &lt;/p&gt;  &lt;h3&gt;Where Do We Call the Service?&lt;/h3&gt;  &lt;p&gt;In &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;Visual Studio LightSwitch&lt;/a&gt; there are a few places where you can place code to validate entities. There are &lt;em&gt;Property&lt;/em&gt;_Validate methods and there are &lt;em&gt;Entity&lt;/em&gt;_Validate methods. &lt;em&gt;Property&lt;/em&gt;_Validate methods run first on the client and then on the server and are good for checking the format of data entered, doing any comparisons to other properties, or manipulating the data based on conditions stored in the entity itself or its related entities. Usually you want to put your validation code here so that users get immediate feedback of any errors before the data is submitted to the server. These methods are contained on the entity classes themselves. (For more detailed information on the LightSwitch Validation Framework see: &lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2010/08/30/overview-of-data-validation-in-lightswitch-applications-prem-ramanathan.aspx" target="_blank"&gt;Overview of Data Validation in LightSwitch Applications&lt;/a&gt;)&lt;/p&gt;  &lt;p&gt;The &lt;em&gt;Entity&lt;/em&gt;_Validate methods only run on the server and are contained in the ApplicationDataService class. This is the perfect place to call an external validation service because it avoids having clients calling external services directly -- instead the LightSwitch middle-tier makes the call. This gives you finer control over your network traffic. Client applications may only be allowed to connect to your intranet internally but you can allow external traffic to the server managing the external connection in one place. &lt;/p&gt;  &lt;h3&gt;Calling Web Services&lt;/h3&gt;  &lt;p&gt;There are a lot of services out there for validating all sorts of data and each service has a different set of requirements. Typically I prefer &lt;a href="http://en.wikipedia.org/wiki/Representational_State_Transfer" target="_blank"&gt;REST-ful services&lt;/a&gt; so that you can make a simple http request (GET) and get some data back. However, you can also add service references like ASMX and WCF services as well. It’s all going to depend on the service you use so you’ll need to refer to their specific documentation. &lt;/p&gt;  &lt;p&gt;To add a service reference to a LightSwitch application, first flip to File View in the Solution Explorer, right-click on the Server project and then select Add Service Reference…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8168.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2783.image_5F00_thumb.png" width="555" height="460" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Enter the service URL and the service proxy classes will be generated for you. You can then call these from server code you write on the ApplicationDataService just like you would in any other application that has a service reference. In the case of calling REST-ful services that return XML feeds, you can simply construct the URL to call and examine the results. Let’s see how to do that.&lt;/p&gt;  &lt;h3&gt;Address Book Example&lt;/h3&gt;  &lt;p&gt;In &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/26/beginning-lightswitch-address-book-sample.aspx" target="_blank"&gt;this sample&lt;/a&gt; we have an Address table where we want to validate the physical address when the data is saved. There are a few address validator services out there to choose from that I could find, but for this example I chose to sign up for a free trial of an &lt;a href="http://www.serviceobjects.com/lookups/address/address-validation-us" target="_blank"&gt;address validation service from ServiceObjects&lt;/a&gt;. They’ve got some &lt;a href="http://trial.serviceobjects.com/av/AddressValidate.asmx?op=ValidateAddress" target="_blank"&gt;nice, simple APIs&lt;/a&gt; and support REST web requests. Once you sign up they give you a License Key that you need to pass into the service.&lt;/p&gt;  &lt;p&gt;A sample request looks like this:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;http://trial.serviceobjects.com/av/AddressValidate.asmx/ValidateAddress?Address=One+Microsoft+Way&amp;amp;Address2=&amp;amp;City=Redmond&amp;amp;State=WA&amp;amp;PostalCode=98052&amp;amp;LicenseKey=12345&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Which gives you back the result:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #844646"&gt;xml &lt;/span&gt;&lt;span style="color: #b96464"&gt;version&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;1.0&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot; &lt;/span&gt;&lt;span style="color: #b96464"&gt;encoding&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;UTF-8&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;Address &lt;/span&gt;&lt;span style="color: #b96464"&gt;xmlns&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;http://www.serviceobjects.com/&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;
&lt;/span&gt;&lt;span style="color: #b96464"&gt;  xmlns:xsi&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;
  &lt;/span&gt;&lt;span style="color: #b96464"&gt;xmlns:xsd&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;http://www.w3.org/2001/XMLSchema&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;Address&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;1 Microsoft Way&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;Address&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;City&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;Redmond&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;City&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;State&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;WA&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;State&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;Zip&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;98052-8300&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;Zip&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;Address2&lt;/span&gt;&lt;span style="color: #6464b9"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;BarcodeDigits&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;980528300997&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;BarcodeDigits&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;CarrierRoute&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;C012&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;CarrierRoute&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;CongressCode&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;08&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;CongressCode&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;CountyCode&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;033&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;CountyCode&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;CountyName&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;King&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;CountyName&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;Fragment&lt;/span&gt;&lt;span style="color: #6464b9"&gt;/&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;Address&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;If you enter a bogus address or forget to specify the City+State or PostalCode then you will get an error result:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #844646"&gt;xml &lt;/span&gt;&lt;span style="color: #b96464"&gt;version&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;1.0&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot; &lt;/span&gt;&lt;span style="color: #b96464"&gt;encoding&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;UTF-8&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;Address &lt;/span&gt;&lt;span style="color: #b96464"&gt;xmlns&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;http://www.serviceobjects.com/&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;
  &lt;/span&gt;&lt;span style="color: #b96464"&gt;xmlns:xsi&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;
  &lt;/span&gt;&lt;span style="color: #b96464"&gt;xmlns:xsd&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;http://www.w3.org/2001/XMLSchema&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;Error&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;Desc&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;Please input either zip code or both city and state.&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;Desc&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;Number&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #555555"&gt;2&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;Number&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #844646"&gt;Location&lt;/span&gt;&lt;span style="color: #6464b9"&gt;/&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;Error&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #844646"&gt;Address&lt;/span&gt;&lt;span style="color: #6464b9"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;So in order to interact with this service we’ll first need to add some assembly references to the Server project. Right-click on the Server project (like shown above) and select “Add Reference” and import System.Web and System.Xml.Linq.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4035.image_5F00_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8156.image_5F00_thumb_5F00_1.png" width="704" height="693" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, flip back to Logical View and open the Address entity in the Data Designer. Drop down the Write Code button to access the Addresses_Validate method. (You could also just open the Server\UserCode\ApplicationDataService code file if you are in File View). &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3872.image_5F00_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3060.image_5F00_thumb_5F00_2.png" width="277" height="423" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First we need to import some namespaces as well as the default XML namespace that is returned in the response. (For more information on XML in Visual Basic please see: &lt;a href="http://msdn.microsoft.com/en-us/library/bb384460.aspx"&gt;Overview of LINQ to XML in Visual Basic&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/tags/xml/article/" target="_blank"&gt;articles here on my blog&lt;/a&gt;.) Then we can construct the URL based on the entity’s Address properties and query the result XML for either errors or the corrected address. If we find an error, we tell LightSwitch to display the validation result to the user on the screen. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Xml.Linq
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Web.&lt;span style="color: #2b91af"&gt;HttpUtility
&lt;/span&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;&amp;lt;&lt;span style="color: #b96464"&gt;xmlns&lt;/span&gt;&lt;span style="color: #6464b9"&gt;=&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #6464b9"&gt;http://www.serviceobjects.com/&lt;/span&gt;&lt;span style="color: #555555"&gt;&amp;quot;&lt;/span&gt;&amp;gt;

&lt;span style="color: blue"&gt;Namespace &lt;/span&gt;LightSwitchApplication
&lt;span style="color: blue"&gt;  Public Class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ApplicationDataService

    &lt;/span&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Addresses_Validate(entity &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Address&lt;/span&gt;, results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntitySetValidationResultsBuilder&lt;/span&gt;)
      &lt;span style="color: blue"&gt;Dim &lt;/span&gt;isValid = &lt;span style="color: blue"&gt;False
      Dim &lt;/span&gt;errorDesc = &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;

      &lt;/span&gt;&lt;span style="color: green"&gt;'Construct the URL to call the web service
      &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;url = &lt;span style="color: blue"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;http://trial.serviceobjects.com/av/AddressValidate.asmx/ValidateAddress?&amp;quot; &lt;/span&gt;&amp;amp;
                              &lt;span style="color: #a31515"&gt;&amp;quot;Address={0}&amp;amp;Address2={1}&amp;amp;City={2}&amp;amp;State={3}&amp;amp;PostalCode={4}&amp;amp;LicenseKey={5}&amp;quot;&lt;/span&gt;,
                              UrlEncode(entity.Address1),
                              UrlEncode(entity.Address2),
                              UrlEncode(entity.City),
                              UrlEncode(entity.State),
                              UrlEncode(entity.ZIP),
                              &lt;span style="color: #a31515"&gt;&amp;quot;12345&amp;quot;&lt;/span&gt;)

      &lt;span style="color: blue"&gt;Try
          &lt;span style="color: green"&gt;'Call the service and load the XML result &lt;/span&gt;&lt;br /&gt;          Dim &lt;/span&gt;addressData = &lt;span style="color: #2b91af"&gt;XElement&lt;/span&gt;.Load(url)

          &lt;span style="color: green"&gt;'Check for errors first
          &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;err = addressData&lt;span style="color: #6464b9"&gt;...&amp;lt;&lt;/span&gt;Error&lt;span style="color: #6464b9"&gt;&amp;gt;
          &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;err.Any &lt;span style="color: blue"&gt;Then
              &lt;/span&gt;errorDesc = err&lt;span style="color: #6464b9"&gt;.&amp;lt;&lt;/span&gt;Desc&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value
          &lt;span style="color: blue"&gt;Else
              &lt;/span&gt;&lt;span style="color: green"&gt;'Fill in corrected address values returned from service
              &lt;/span&gt;entity.Address1 = addressData&lt;span style="color: #6464b9"&gt;.&amp;lt;&lt;/span&gt;Address&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value
              entity.Address2 = addressData&lt;span style="color: #6464b9"&gt;.&amp;lt;&lt;/span&gt;Address2&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value
              entity.City = addressData&lt;span style="color: #6464b9"&gt;.&amp;lt;&lt;/span&gt;City&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value
              entity.State = addressData&lt;span style="color: #6464b9"&gt;.&amp;lt;&lt;/span&gt;State&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value
              entity.ZIP = addressData&lt;span style="color: #6464b9"&gt;.&amp;lt;&lt;/span&gt;Zip&lt;span style="color: #6464b9"&gt;&amp;gt;&lt;/span&gt;.Value
              isValid = &lt;span style="color: blue"&gt;True
          End If

      Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Exception
          Trace&lt;/span&gt;.TraceError(ex)
      &lt;span style="color: blue"&gt;End Try

      If Not &lt;/span&gt;(isValid) &lt;span style="color: blue"&gt;Then
          &lt;/span&gt;results.AddEntityError(&lt;span style="color: #a31515"&gt;&amp;quot;This is not a valid US address. &amp;quot; &lt;/span&gt;&amp;amp; errorDesc)
      &lt;span style="color: blue"&gt;End If
    End Sub
  End Class
End Namespace&lt;/span&gt;&lt;/pre&gt;

&lt;h3&gt;Run it!&lt;/h3&gt;

&lt;p&gt;Now that I’ve got this code implemented let’s enter some addresses on our contact screen. Here I’ve entered three addresses, the first two are legal and the last one is not. Also notice that I’ve only specified partial addresses.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6014.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4454.image_5F00_thumb_5F00_3.png" width="637" height="299" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I try to save this screen, an error will be returned from the service on the last row. LightSwitch won’t let us save until the address is fixed.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3056.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5444.image_5F00_thumb_5F00_4.png" width="633" height="323" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I delete the bogus address and save again, you will see that the other addresses were verified and all the fields are updated with complete address information.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/23602.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3872.image_5F00_thumb_5F00_5.png" width="631" height="274" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;&lt;/h3&gt;

&lt;h3&gt;Wrap Up&lt;/h3&gt;

&lt;p&gt;I hope this gives you a good idea on how to implement web service calls into the LightSwitch validation pipeline. Even though each service you use will have different requirements on how to call them and what they return, the LightSwitch validation pipeline gives you the necessary hooks to implement complex entity validation easily. &lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10261345" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Validation" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Validation/" /></entry><entry><title>Beginning LightSwitch–Address Book Sample</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/26/beginning-lightswitch-address-book-sample.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2012/01/26/beginning-lightswitch-address-book-sample.aspx</id><published>2012-01-26T20:48:13Z</published><updated>2012-01-26T20:48:13Z</updated><content type="html">&lt;p&gt;Some folks have been asking for this so I just released the completed Address Book sample that you build step-by-step in the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/01/beginning-lightswitch-getting-started.aspx"&gt;Beginning LightSwitch Article Series&lt;/a&gt;. &lt;/p&gt;  &lt;h3&gt;&lt;a href="http://code.msdn.microsoft.com/Begining-LightSwitch-508763ea" target="_blank"&gt;&lt;img border="0" alt="Download Sample" src="http://i.msdn.microsoft.com/ee402630.Download_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt;&amp;#160;&lt;a href="http://code.msdn.microsoft.com/Begining-LightSwitch-508763ea" target="_blank"&gt;Download the Address Book Sample&lt;/a&gt;&lt;/h3&gt;  &lt;h3&gt;Read the Series&lt;/h3&gt;  &lt;p&gt;Are you completely new to LightSwitch and software development? Read this entry-level article series to get started with the most important concepts you need to build any LightSwitch application.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx"&gt;Part 1: What’s in a Table? Describing Your Data&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/08/beginning-lightswitch-part-2-feel-the-love-defining-data-relationships.aspx"&gt;Part 2: Feel the Love. Defining Data Relationships&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/14/beginning-lightswitch-part-3-screen-templates-which-one-do-i-choose.aspx"&gt;Part 3: Screen Templates, Which One Do I Choose?&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/15/beginning-lightswitch-part-4-too-much-information-sorting-and-filtering-data-with-queries.aspx"&gt;Part 4: Too much information! Sorting and Filtering Data with Queries&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/20/beginning-lightswitch-part-5-may-i-defining-user-permissions.aspx"&gt;Part 5: May I? Controlling Access with User Permissions&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/21/beginning-lightswitch-part-6-i-feel-pretty-customizing-the-quot-look-and-feel-quot-with-themes.aspx"&gt;Part 6: I Feel Pretty! Customizing the &amp;quot;Look and Feel&amp;quot; with Themes&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;More Information&lt;/h3&gt;  &lt;p&gt;Visit the &lt;a href="http://msdn.com/lightswitch"&gt;LightSwitch Developer Center&lt;/a&gt; to download LightSwitch and get started learning.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=211226"&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/ee402630.Numeral1_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=211226"&gt;Download Visual Studio LightSwitch&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823"&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/ee402630.Numeral2_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823"&gt;Watch the instructional LightSwitch &amp;quot;How Do I?&amp;quot; videos&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857"&gt;&lt;img border="0" alt="Get essential training" src="http://i.msdn.microsoft.com/ee402630.Numeral3_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857"&gt;Get essential training&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-us/category/vslightswitch"&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/ee402630.Numeral4_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-us/category/vslightswitch"&gt;Ask questions in the LightSwitch forums&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10260990" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Samples" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Samples/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Beginning LightSwitch Series" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Beginning+LightSwitch+Series/" /></entry><entry><title>Using Different Edit Screens Based on Record Types (Table Inheritance)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/20/using-different-edit-screens-based-on-record-types-table-inheritance.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2012/01/20/using-different-edit-screens-based-on-record-types-table-inheritance.aspx</id><published>2012-01-20T14:59:00Z</published><updated>2012-01-20T14:59:00Z</updated><content type="html">&lt;p&gt;I had a reader ask a question this week on how to use &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;Visual Studio LightSwitch&lt;/a&gt; to open different Edit Detail screens based on the “type” of record. This is a very common thing to do especially for data models that use table inheritance (or sub-tables). For instance say we are building an application for a pet store to manage their inventory of animals. We need to collect shared properties of all the animals in an Animal table but we also want to set up table inheritance to Fish, Cat and Dog tables which collect specific properties of those types of animals. When a user selects an animal on a search screen, we need to display a screen that lets them work with the correct data from the specific table. LightSwitch provides a “Show as Link” on labels which automatically opens up the default details screen for that entity, but in our case we could have multiple screens. There are also a few techniques you need to know when dealing with these types of relationships in LightSwitch, particularly around the insert pipeline. In this post I will show you how you can achieve this functionality. &lt;/p&gt;  &lt;h3&gt;Create The Data Model&lt;/h3&gt;  &lt;p&gt;First let’s start by creating a simple inheritance data model for the pet store. We will build an Animal table that collects general properties of any animal in the store. Then we will build Cat, Dog and Fish tables to collect specific properties of those types of animals. The relationship between the Animal table and the others will be a ‘one to zero or one’ relationship. &lt;/p&gt;  &lt;p&gt;For this example, the Animal table has two required properties, Name and Type. Type is a Choice List with the static values “Cat”, “Dog”, “Fish” to correspond to the type of record the animal is. We will use this to drive what records are inserted into which specific table as well as use it to determine which screens to display. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0116.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7382.image_5F00_thumb.png" width="677" height="507" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next, create the Cat, Dog and Fish tables to collect properties specific to these types of animals.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6403.image_5F00_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2570.image_5F00_thumb_5F00_1.png" width="701" height="436" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Finally, set up the relationships from Animal to these tables as a “one to zero or one” relationship with a delete behavior of “Cascade Delete”.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8037.image_5F00_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3644.image_5F00_thumb_5F00_2.png" width="500" height="488" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Our data model now looks like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5707.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3247.image_5F00_thumb_5F00_3.png" width="661" height="491" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Create the Screens&lt;/h3&gt;  &lt;p&gt;Next we’ll need to enter new animals into the system. Create a New Data Screen and select Animal as the screen data. When you do this, LightSwitch will include all the one-to-one related tables as fields on the screen. However, we only want to require the user to enter the general Animal properties on this screen. Once they save, we will direct them to the correct Cat, Dog or Fish detail screen. So first delete all the items in the content tree of the Screen Designer except for Name and Type.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8831.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3666.image_5F00_thumb_5F00_4.png" width="506" height="248" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next, create an Edit Details Screen and select the &lt;strong&gt;Animal&lt;/strong&gt; screen data again. Name the screen CatDetail and &lt;strong&gt;uncheck &lt;/strong&gt;“Use as Default Details Screen”.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6862.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4237.image_5F00_thumb_5F00_5.png" width="706" height="503" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Again you will see that LightSwitch reads these special relationships and adds all the fields from all four tables to the screen. We will need to make some changes. First, change the “Type” from an Auto Complete box to a Label. Once the user has entered the type of animal on the New Data screen, it cannot be changed. Next, delete all the fields related to Dog and Fish from the screen. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4705.image_5F00_14.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4621.image_5F00_thumb_5F00_6.png" width="464" height="299" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Repeat the same process to create the DogDetail and FishDetail screens, removing the fields from the screen that do not belong. &lt;/p&gt;  &lt;p&gt;Finally, add a Search Data Screen and select the Animal as the screen data again. Select the “Name” content item and in the properties window uncheck “Show as Link”. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8422.image_5F00_20.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6036.image_5F00_thumb_5F00_9.png" width="692" height="241" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Instead of using the built-in “Show as Link” functionality, we need to create our own command. We can put commands anywhere on the screen and we can show them as buttons or links. (For more information see: &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/06/i-command-you-lightswitch-screen-commands-tips-amp-tricks.aspx" target="_blank"&gt;“I Command You!” - LightSwitch Screen Commands Tips &amp;amp; Tricks&lt;/a&gt;) For instance we could put an edit button on the screen command bar, the grid command bar, or even in the row itself. Let’s add a command into the row itself.&lt;/p&gt;  &lt;p&gt;Right-click on the Data Grid Row Command Bar in the content tree and select “Add Button…”. Create a new method called “Edit”.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6763.image_5F00_18.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0083.image_5F00_thumb_5F00_8.png" width="411" height="231" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We want to show the command as a link instead of a button so select the button in the content tree and change it to a link.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3323.image_5F00_22.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0576.image_5F00_thumb_5F00_10.png" width="489" height="294" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Write the Code&lt;/h3&gt;  &lt;p&gt;Now we need to write some code to pull this all together. Right-click on the button we just created and select “Edit Execute Code” to open the code editor. Here we will check what type of animal we have to open the corresponding screen.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Edit_Execute()
    &lt;span style="color: blue"&gt;If Me&lt;/span&gt;.Animals.SelectedItem &lt;span style="color: blue"&gt;IsNot Nothing Then
        Select Case Me&lt;/span&gt;.Animals.SelectedItem.Type
            &lt;span style="color: blue"&gt;Case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Cat&amp;quot;
                &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Application.ShowCatDetail(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Animals.SelectedItem.Id)
            &lt;span style="color: blue"&gt;Case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Dog&amp;quot;
                &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Application.ShowDogDetail(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Animals.SelectedItem.Id)
            &lt;span style="color: blue"&gt;Case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Fish&amp;quot;
                &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Application.ShowFishDetail(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Animals.SelectedItem.Id)
        &lt;span style="color: blue"&gt;End Select
    End If
End Sub&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Next we need to write similar code on the New Data screen so that it opens the correct detail screen after the user saves a new animal record. Open the CreateNewAnimal screen and in the upper right drop down the “Write Code” button and select the CreateNewAnimal_Saved method. First comment out the call to ShowDefaultScreen and then write code to determine which screen we need to show instead:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;CreateNewAnimal_Saved()
&lt;span style="color: blue"&gt;    Me&lt;/span&gt;.Close(&lt;span style="color: blue"&gt;False&lt;/span&gt;)
    &lt;span style="color: green"&gt;'Application.Current.ShowDefaultScreen(Me.AnimalProperty)

    &lt;/span&gt;&lt;span style="color: blue"&gt;Select Case Me&lt;/span&gt;.AnimalProperty.Type
        &lt;span style="color: blue"&gt;Case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Cat&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Application.ShowCatDetail(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.AnimalProperty.Id)
        &lt;span style="color: blue"&gt;Case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Dog&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Application.ShowDogDetail(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.AnimalProperty.Id)
        &lt;span style="color: blue"&gt;Case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Fish&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Application.ShowFishDetail(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.AnimalProperty.Id)
    &lt;span style="color: blue"&gt;End Select
End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Finally, we need to implement a business rule on Animal in the save pipeline. This rule is important so that a new record is added to the correct table based on the animal’s type. That way after the user saves the CreateNewAnimal screen, a record will be written to the correct table and the detail screen will open and allow the user to edit the specific fields in the Cat, Dog or Fish table. Double-click on Animals in the Solution Explorer under the Data Sources/ApplicationData node to open the Data Designer. Drop down the Write Code button and select the Animals_Inserting method and write this code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Animals_Inserting(entity &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Animal&lt;/span&gt;)
    &lt;span style="color: blue"&gt;Select Case &lt;/span&gt;entity.Type
        &lt;span style="color: blue"&gt;Case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Cat&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;entity.Cat &lt;span style="color: blue"&gt;Is Nothing Then
                &lt;/span&gt;entity.Cat = &lt;span style="color: blue"&gt;New &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Cat&lt;/span&gt;()
            &lt;span style="color: blue"&gt;End If
        Case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Dog&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;entity.Dog &lt;span style="color: blue"&gt;Is Nothing Then
                &lt;/span&gt;entity.Dog = &lt;span style="color: blue"&gt;New &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dog&lt;/span&gt;()
            &lt;span style="color: blue"&gt;End If
        Case &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Fish&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;entity.Fish &lt;span style="color: blue"&gt;Is Nothing Then
                &lt;/span&gt;entity.Fish = &lt;span style="color: blue"&gt;New &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Fish&lt;/span&gt;()
            &lt;span style="color: blue"&gt;End If
    End Select
End Sub&lt;/span&gt;&lt;/pre&gt;


&lt;h3&gt;Run it!&lt;/h3&gt;

&lt;p&gt;Enter new animals on the Create New Animal screen and when you click Save, the correct detail screen will open allowing you to enter more specific details based on the type of animal.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5850.image_5F00_26.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6443.image_5F00_thumb_5F00_12.png" width="546" height="199" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On our search screen, we can click the Edit link on any of the rows and it will open to the correct details screen as well.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2543.image_5F00_28.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1641.image_5F00_thumb_5F00_13.png" width="543" height="213" /&gt;&lt;/a&gt;&lt;/p&gt;





&lt;h3&gt;Wrap Up&lt;/h3&gt;

&lt;p&gt;I hope this post answered the reader’s question on how to open different detail screens depending on the record’s type. All it takes is implementing your own command. I also touched on one to one relationships and how to set up basic table inheritance. I encourage you to experiment more with this type of relationship. They come in particularly handy when you need to extend external data sources with additional properties or when you need to set up inheritance hierarchies. The trick is to get a record inserted into the right table when you insert the master / parent record. I’ll expand on a couple other techniques in a future post.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10258714" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="Data" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Data/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Screens" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Screens/" /></entry><entry><title>Creating Cascading Drop Down Lists in Visual Studio LightSwitch</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/12/creating-cascading-drop-down-lists-in-visual-studio-lightswitch.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2012/01/12/creating-cascading-drop-down-lists-in-visual-studio-lightswitch.aspx</id><published>2012-01-12T18:15:49Z</published><updated>2012-01-12T18:15:49Z</updated><content type="html">  &lt;p&gt;A common technique on data entry screens is using one “drop down list” (called an auto-complete box in LightSwitch) as a filter into the next. This limits the amount of choices that need to be brought down and guides the user into easily locating values. This technique is also useful if you have cascading filtered lists where the first selection filters data in the second, which filters data in the next, and so forth. LightSwitch makes this easy to do using parameterized queries and parameter binding. In this post let’s take a look a couple common scenarios. &lt;/p&gt;  &lt;h3&gt;Cascading Lists based on Multiple Tables&lt;/h3&gt;  &lt;p&gt;Let’s take an example where we have a table of States and a child table of Cities. Cities are then selected on Customers when entering them into the system. So we have one-to-many relationships between State and Cities and City and Customers. Our data model looks like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4744.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6646.image_5F00_thumb.png" width="780" height="422" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;When the user is entering new customers we don’t want to display thousands of cities in the dropdown to choose from. Although the users can use the auto-complete box feature to locate a city, bringing down all these records affects performance. It’s better to either use a Modal Window Picker search dialog (&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/09/15/filtering-lookup-lists-with-large-amounts-of-data-on-data-entry-screens.aspx" target="_blank"&gt;like I showed in this article&lt;/a&gt;) or present the list of States first and then filter the list of Cities down based on that selection. &lt;/p&gt;  &lt;p&gt;First we need to create a couple queries. The first will simply sort the list of States so that they show up in alphabetical order in the list. Right-click on the States table in the Solution Explorer and Add Query to open the Query Designer. Create a query called “SortedStates” that sorts on the state’s Name Ascending:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6330.image_5F00_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5756.image_5F00_thumb_5F00_2.png" width="655" height="274" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next create a query called “CitiesByState” by right-clicking on the Cities table in the Solution Explorer and selecting Add Query again. This time we will create a parameterized query: &lt;strong&gt;Where&lt;/strong&gt; the &lt;strong&gt;State.Id&lt;/strong&gt; property&lt;strong&gt; is equal to&lt;/strong&gt; a &lt;strong&gt;new parameter&lt;/strong&gt; called &lt;strong&gt;Id&lt;/strong&gt;. The Query Designer should now look like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4274.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7206.image_5F00_thumb_5F00_3.png" width="482" height="302" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now create the Customer Detail Screen like normal. Right-click on the Screens node and select “Add Screen…”, select the Edit Details Screen template then choose Customers for the screen data. The Screen Designer opens and all the fields in the Customer entity will be in the content tree. The City field is displayed as an auto-complete box. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2514.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7317.image_5F00_thumb_5F00_4.png" width="507" height="272" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next we’ll need to add a data item to our screen for tracking the selected State. We will use this value to determine the filter on the City list so that users only see cities in the selected state. Click “Add Data Item” and add a Local Property of type State called SelectedState.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7801.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7875.image_5F00_thumb_5F00_5.png" width="498" height="497" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next, drag the SelectedState over onto the content tree above the City. LightSwitch will automatically create an auto-complete box control for you.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3678.image_5F00_14.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3187.image_5F00_thumb_5F00_6.png" width="476" height="345" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Since we want to display the states sorted, next add the SortedStates query to the screen. Click “Add Data Item” again, this time select Query and choose SortedStates.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2514.image_5F00_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8473.image_5F00_thumb_5F00_7.png" width="503" height="501" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then select the SelectedState auto-complete box in the content tree and on the Properties window, set the Choices property to SortedStates.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5238.image_5F00_18.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0042.image_5F00_thumb_5F00_8.png" width="288" height="391" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next, add the CitiesByState query to the screen and set that as the Choices property of the Cities auto-complete box. Again, click “Add Data Item” and choose the CitiesByState query.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4744.image_5F00_20.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5153.image_5F00_thumb_5F00_9.png" width="501" height="500" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then select the Cities auto-complete box and set the Choices property to this query.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5228.image_5F00_22.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5241.image_5F00_thumb_5F00_10.png" width="288" height="390" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Lastly we need to hook up the parameter binding. Select the Id parameter of the CitiesByState query and in the properties window set the Parameter Binding to SelectedState.Id. Once you do this a grey arrow on the left side will indicate the binding.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7801.image_5F00_24.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3755.image_5F00_thumb_5F00_11.png" width="546" height="258" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Once you set the value of a query parameter, LightSwitch will automatically execute the query for you so you don’t need to write any code for this. Hit F5 and see what you get. Notice that the Cities drop down list is empty until you select a State at which point it feeds the CitiesByState query and executes it. Also notice that if you make a city selection and then change the state, the selection is still displayed correctly, it doesn’t disappear. Just keep in mind that anytime a user changes the state, the city query is re-executed against the server.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8468.image_5F00_26.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8867.image_5F00_thumb_5F00_12.png" width="614" height="265" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;One additional thing that you might want to do is to initially display the state to which the city belongs. As it is, the Selected State comes up blank when the screen is opened. This is because it is bound to a screen property which is not backed by data. However we can easily set the initial value of the SelectedState in code. Back in the Screen Designer drop down the “Write Code” button at the top right and select the InitializeDataWorkspace method and write the following:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;CustomerDetail_InitializeDataWorkspace(saveChangesTo &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;(&lt;span style="color: blue"&gt;Of &lt;/span&gt;Microsoft.LightSwitch.&lt;span style="color: #2b91af"&gt;IDataService&lt;/span&gt;))
&lt;span style="color: green"&gt;&lt;font color="#333333"&gt;    &lt;/font&gt;' Write your code here.
   &lt;strong&gt; &lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="color: blue"&gt;If Me&lt;/span&gt;.Customer.City &lt;/strong&gt;&lt;strong&gt;&lt;span style="color: blue"&gt;IsNot Nothing Then
        Me&lt;/span&gt;.SelectedState = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.Customer.City.State
    &lt;/strong&gt;&lt;span style="color: blue"&gt;&lt;strong&gt;End If&lt;/strong&gt;
End Sub&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now when you run the screen again, the Selected State will be displayed.&lt;/p&gt;

&lt;h3&gt;Cascading Lists Based on a Single Table&lt;/h3&gt;

&lt;p&gt;Another option is to create cascading lists based on a single table. For instance say we do not want to have a State table at all. Instead it may make more sense to store the State on the City. So our data model could be simplified by having just a City table related to many Customers. &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5228.image_5F00_28.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1031.image_5F00_thumb_5F00_13.png" width="711" height="375" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This time when we create a parameterized query called CitesByState, we’ll set it up &lt;strong&gt;Where &lt;/strong&gt;the &lt;strong&gt;State &lt;/strong&gt;is &lt;strong&gt;equal to &lt;/strong&gt;a &lt;strong&gt;new parameter &lt;/strong&gt;called &lt;strong&gt;State.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7382.image_5F00_30.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6305.image_5F00_thumb_5F00_14.png" width="466" height="302" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the screen, select “Add Data Item” to add the CitiesByState to the screen and set it as the Choices property of the City auto-complete box just like before.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5722.image_5F00_32.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0535.image_5F00_thumb_5F00_15.png" width="715" height="494" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This time, however, the State is the query parameter we need to bind. Add a string screen property to the screen to hold the selected state. Click “Add Data Item” again, add a required Local Property of type String and name it SelectedState. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1033.image_5F00_34.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1018.image_5F00_thumb_5F00_16.png" width="505" height="504" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Drag the SelectedState onto the content tree above the City. This time LightSwitch will create a textbox for us since this is just a local string property. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4645.image_5F00_38.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5734.image_5F00_thumb_5F00_18.png" width="765" height="467" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, we need to set up the query parameter binding. Select the State query parameter and in the properties window set the Parameter Binding to SelectedState.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8461.image_5F00_40.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2117.image_5F00_thumb_5F00_19.png" width="549" height="196" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to set the SelectedState when the screen opens, the same code as before will work. Now when we run this, you will see a textbox that will filter the list of cities. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8468.image_5F00_42.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7701.image_5F00_thumb_5F00_20.png" width="609" height="253" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, this may not be exactly what we want. If the user has a free-form text field then they could mistype a state code and the query would return no results. It would be better to present the states in a auto-complete box like before. Close the application and open the Screen Designer again. Select the SelectedState screen property. Notice in the properties window you can display this as a static list of values by creating a Choice List. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6724.image_5F00_46.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0451.image_5F00_thumb_5F00_22.png" width="555" height="276" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enter the states that the user should select from and then run the application again. Now we get an auto-complete box like before. However, this approach leaves us having to define the choice list of states on every screen we want this functionality. The first approach using a State table solves this issue but there is also one other approach we could take to avoid having to create a separate table. &lt;/p&gt;

&lt;h3&gt;Using a Choice List on the Entity &lt;/h3&gt;

&lt;p&gt;We could improve this situation by defining the choice list of states on the Customer entity. Then we would only have to define the lists of states in one place. Create a State property on the Customer using the Data Designer and on the properties window select Choice List and specify the list of states there. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6712.image_5F00_48.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1524.image_5F00_thumb_5F00_23.png" width="769" height="412" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now add a new detail screen for Customer and you will see the State and City properties are set up as auto-complete boxes. Next add the CitiesByState query to the screen by clicking “Add Data Item” like before. We can use the same CitiesByState query as the previous example. Select the City auto-complete box and in the properties window set the Choices property to CitiesByState like before. &lt;/p&gt;

&lt;p&gt;The difference is the query parameter binding. Select the State query parameter on the left and in the properties window set the Parameter Binding to Customer.State.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7875.image_5F00_50.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7888.image_5F00_thumb_5F00_24.png" width="528" height="449" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With this technique, you also do not need to write any code to set the initial selected State because we are now storing that value on the Customer record. Run the application again and the screen should behave the same. The only difference now is that we are storing the State on the Customer instead of a separate table. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3175.image_5F00_55.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6712.image_5F00_thumb_5F00_26.png" width="611" height="254" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This technique is the simplest to set up, so if you have a lot of Customer screens, then this may be the best choice for you if you have a static list of values like States. However if you have dynamic list of values then it’s better to store these in a separate table like the first technique showed. &lt;/p&gt;

&lt;p&gt;For more information on filtering data and configuring lists see:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/08/04/how-to-create-a-multi-column-auto-complete-drop-down-box-in-lightswitch.aspx"&gt;How to Create a Multi-Column Auto-Complete Drop-down Box in LightSwitch&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/08/16/how-to-allow-adding-of-data-to-an-auto-complete-drop-down-box-in-lightswitch.aspx"&gt;How to Allow Adding of Data to an Auto-Complete Drop-down Box in LightSwitch&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/09/15/filtering-lookup-lists-with-large-amounts-of-data-on-data-entry-screens.aspx" target="_blank"&gt;Filtering Lookup Lists with Large Amounts of Data on Data Entry Screens&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10256033" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="Data" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Data/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Screens" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Screens/" /></entry><entry><title>LightSwitch Community &amp; Content Rollup– December 2011</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2012/01/05/lightswitch-community-amp-content-rollup-december-2011.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2012/01/05/lightswitch-community-amp-content-rollup-december-2011.aspx</id><published>2012-01-05T14:55:00Z</published><updated>2012-01-05T14:55:00Z</updated><content type="html">&lt;p&gt;&lt;strong&gt;Happy New Year everyone! &lt;/strong&gt;I hope you all had a wonderful holiday and enjoyed some well-deserved time off. I sure did! Now that I’m back in the office I’m a few days overdue for this post so here ya go! A few months ago I started posting a rollup of interesting community happenings, content, samples and extensions popping up around &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;Visual Studio LightSwitch&lt;/a&gt;. If you missed those rollups you can check them out here: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/09/29/lightswitch-community-amp-content-rollup-september.aspx"&gt;LightSwitch Community &amp;amp; Content Rollup–September 2011&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/31/lightswitch-community-amp-content-rollup-october-2011.aspx"&gt;LightSwitch Community &amp;amp; Content Rollup–October 2011&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/11/30/lightswitch-community-amp-content-rollup-november-2011.aspx" target="_blank"&gt;LightSwitch Community &amp;amp; Content Rollup–November 2011&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Usually December is a pretty slow month all around, but there were still a lot of awesome things around LightSwitch, especially the number of community articles this month! Check them out…&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;“LightSwitch Star” Contest&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=232292"&gt;&lt;img style="margin: 0px 5px 5px 0px" border="0" alt="“LightSwitch Star” Contest on CodeProject" align="left" src="http://i.msdn.microsoft.com/ff796201.LightSwitchStarContest(en-us,MSDN.10).jpg" /&gt;&lt;/a&gt;&lt;em&gt;Do you have what it takes to be a &lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx" target="_blank"&gt;LightSwitch Star&lt;/a&gt;? Show us your coolest, most productive, LightSwitch business application and &lt;/em&gt;&lt;strong&gt;&lt;i&gt;you could win a Laptop &lt;/i&gt;&lt;/strong&gt;&lt;em&gt;and other great prizes!&amp;#160; &lt;/em&gt;&lt;/p&gt;  &lt;p&gt;In November The Code Project launched the &lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;“LightSwitch Star” contest&lt;/a&gt;. You just answer some questions and email them a screenshot or two. They’re looking for apps that show off the most productivity in a business as well as apps that use extensions in a unique, innovative way. Prizes are given away each month (&lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx#judging" target="_blank"&gt;see here for more details on prizes&lt;/a&gt;). In early December they announced the&lt;strong&gt; &lt;/strong&gt;November winners and today they announced the December winners in each category: &lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="300"&gt;&lt;b&gt;Most Efficient Business Application&lt;/b&gt;&lt;/td&gt;        &lt;td valign="top" width="300"&gt;&lt;b&gt;Most Ground-breaking Business Application&lt;/b&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="300"&gt;&lt;em&gt;November&lt;/em&gt; &lt;/td&gt;        &lt;td valign="top" width="300"&gt;&lt;em&gt;November&lt;/em&gt; &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="300"&gt;1st prize: &lt;a href="http://www.codeproject.com/KB/LightSwitch/SecurityCentral.aspx"&gt;Security Central&lt;/a&gt;           &lt;br /&gt;2nd prize: &lt;a href="http://www.codeproject.com/KB/LightSwitch/PTA-LightSwitch.aspx"&gt;PTA LightSwitch&lt;/a&gt; &lt;/td&gt;        &lt;td valign="top" width="300"&gt;1st prize: &lt;a href="http://www.codeproject.com/KB/LightSwitch/Church.aspx"&gt;Church+&lt;/a&gt;           &lt;br /&gt;2nd prize: &lt;a href="http://www.codeproject.com/KB/LightSwitch/Engineeringapp.aspx"&gt;Engineering App&lt;/a&gt; &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="300"&gt;&lt;em&gt;December&lt;/em&gt;&lt;/td&gt;        &lt;td valign="top" width="300"&gt;&lt;em&gt;December&lt;/em&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="300"&gt;1st prize: &lt;a href="http://www.codeproject.com/KB/LightSwitch/Patient-Tracker.aspx"&gt;Patient Tracker&lt;/a&gt;           &lt;br /&gt;2nd prize: &lt;a href="http://www.codeproject.com/KB/LightSwitch/Instant-Assets.aspx"&gt;Instant Assets&lt;/a&gt; &lt;/td&gt;        &lt;td valign="top" width="300"&gt;1st prize: &lt;a href="http://www.codeproject.com/KB/LightSwitch/Health-Safety-System.aspx"&gt;Health and Safety Management System&lt;/a&gt;           &lt;br /&gt;2nd prize: &lt;a href="http://www.codeproject.com/KB/LightSwitch/Orion.aspx"&gt;Orion&lt;/a&gt; &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Congrats to all! Can’t wait to see what people submit in January. There were some &lt;strong&gt;really cool &lt;/strong&gt;applications submitted in December. Here’s a breakdown of what was submitted last month (see all &lt;a href="http://www.codeproject.com/KB/LightSwitch/#LightSwitch+Star+Contest" target="_blank"&gt;23 apps that have been submitted so far here&lt;/a&gt;). Make sure to vote for your favorite ones, grand prize is a laptop!&lt;/p&gt;  &lt;p&gt;&lt;b&gt;7 More Production Apps…&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a name="artTitle"&gt;&lt;/a&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/Instant-Assets.aspx" name="artTitle"&gt;Instant Assets&lt;/a&gt; - The one stop shop for all your asset, equipment and facilities management needs &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/Patient-Tracker.aspx" name="artTitle"&gt;Patient Tracker&lt;/a&gt; - used to interface to a SharePoint list (used as the dataset) to provide timestamp and delay code inputs to the SharePoint list. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/PeopleTrac.aspx" name="artTitle"&gt;PeopleTrac – People Management for Not-For-Profit Organizations&lt;/a&gt; - Demonstrates several LightSwitch capabilities including WCF-RIA services, Native SQL, Name and Addres merge purge &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/HSMS_LightSwitch.aspx" name="artTitle"&gt;The Health and Safety Management System&lt;/a&gt; - The Health and Safety Management System is an application that is used to help organizations better manage and mitigate health and safety statistics and KPIs. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/Orion.aspx" name="artTitle"&gt;Orion&lt;/a&gt; - A mini-CRM that helps with POS records, service request, field technicians workload, inventory, inventory tracking, fuel management and reports. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/SearchSSRSSubscriptions.aspx" name="artTitle"&gt;Search SSRS Subscriptions – &lt;/a&gt;Manages subscriptions to SQL Server Reporting Services &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/LSWinDevNews.aspx" name="artTitle"&gt;WindowsDevNews.com: A Visual Studio LightSwitch Application&lt;/a&gt; – WindowsDevNews.com site uses Visual Studio LightSwitch for it's back-end &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;3 More Tutorials/Samples/Videos…&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/LSHelpDesk.aspx" name="artTitle"&gt;An Advanced Visual Studio LightSwitch Application&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/Health-Safety-System.aspx" name="artTitle"&gt;Health and Safety Management System (Tutorial)&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.youtube.com/watch?v=LSC0ilCHgbc&amp;amp;list=UUgFBc_I8vOTYjXOj0uyQTJA&amp;amp;index=1&amp;amp;feature=plcp"&gt;YouTube Video - Using LightSwitch with MySQL&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/7521c496-abd6-47fb-91ac-e6f834aaeb39"&gt;ComponentOne Scheduler for LightSwitch Released &lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0677.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 29px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="left" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3821.image_5F00_thumb.png" width="175" height="105" /&gt;&lt;/a&gt;&lt;a href="http://www.componentone.com/" target="_blank"&gt;ComponentOne&lt;/a&gt; released another LightSwitch extension last month in addition to the &lt;a href="http://visualstudiogallery.msdn.microsoft.com/b9072625-0b1d-4e69-b209-26ff2aa154d6" target="_blank"&gt;OLAP Control&lt;/a&gt;. This ready-to-use LightSwitch screen gives you a complete Outlook-style scheduling application! Check it out:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://demo.componentone.com/LightSwitch/Scheduler/" target="_blank"&gt;Live Demo!&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/7521c496-abd6-47fb-91ac-e6f834aaeb39" target="_blank"&gt;Product Details&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;   &lt;br /&gt;Notable Content this Month&lt;/h3&gt;  &lt;p&gt;Here’s some more of the fun things the team and community released in December. &lt;/p&gt;  &lt;h6&gt;Extensions released in December (&lt;a href="http://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=SearchText&amp;amp;f%5B0%5D.Value=LightSwitch&amp;amp;sortBy=Date" target="_blank"&gt;see all 71 of them here!&lt;/a&gt;):&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/217442d4-3bb5-4a9f-b7ae-d944eeda7022"&gt;Background Group Layout Extension &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/7521c496-abd6-47fb-91ac-e6f834aaeb39"&gt;ComponentOne Scheduler for LightSwitch &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/df61b7a8-f3dc-4e91-a544-76acbcc465e9"&gt;Extended Text Box Extension &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/5b064b35-cdf5-46aa-909f-fa43ad98b512"&gt;Image Button Extension &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/75c9ac60-d84a-47f4-b255-d4034cb07547"&gt;Light Brown Theme &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/16edc12f-71bc-4fb0-a648-93b202906134"&gt;Spursoft Context Menu Commands &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Build your own extensions by visiting the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh304488"&gt;LightSwitch Extensibility page&lt;/a&gt; on the &lt;a href="http://msdn.com/lightswitch"&gt;LightSwitch Developer Center&lt;/a&gt;. &lt;/p&gt;  &lt;h6&gt;Team Articles:&lt;/h6&gt;  &lt;p&gt;In December I kicked off a &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/tags/beginning+lightswitch+series/" target="_blank"&gt;series aimed at beginner developers&lt;/a&gt; just getting started with LightSwitch and was featured in the &lt;a href="http://msdn.microsoft.com/en-us/hh708735" target="_blank"&gt;MSDN Flash Newsletter&lt;/a&gt;. This brought A LOT of traffic to my blog – in fact, it is at &lt;strong&gt;an all-time high&lt;/strong&gt; since the month of December! WOW! This series is popular!&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/01/beginning-lightswitch-getting-started.aspx"&gt;Part 0: Getting Started Resources&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx"&gt;Part 1: What’s in a Table? Describing Your Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/08/beginning-lightswitch-part-2-feel-the-love-defining-data-relationships.aspx"&gt;Part 2: Feel the Love. Defining Data Relationships&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/14/beginning-lightswitch-part-3-screen-templates-which-one-do-i-choose.aspx"&gt;Part 3: Screen Templates, Which One Do I Choose?&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/15/beginning-lightswitch-part-4-too-much-information-sorting-and-filtering-data-with-queries.aspx"&gt;Part 4: Too much information! Sorting and Filtering Data with Queries&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/20/beginning-lightswitch-part-5-may-i-defining-user-permissions.aspx"&gt;Part 5: May I? Controlling Access with User Permissions&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/21/beginning-lightswitch-part-6-i-feel-pretty-customizing-the-quot-look-and-feel-quot-with-themes.aspx"&gt;Part 6: I Feel Pretty! Customizing the &amp;quot;Look and Feel&amp;quot; with Themes&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Matt Thalman also wrote the following article that address a top request in the &lt;a href="http://bit.ly/LightSwitchForums" target="_blank"&gt;LightSwitch Forums&lt;/a&gt;:     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/12/08/creating-a-custom-login-page-matt-thalman.aspx" target="_blank"&gt;Creating a Custom Login Page for a LightSwitch Application&lt;/a&gt;&lt;/p&gt;  &lt;h6&gt;Community Articles:&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/85/A-Groundbreaking-Control-ComponentOne-Scheduler-LightSwitch-Extension.aspx"&gt;A Groundbreaking Control - ComponentOne Scheduler LightSwitch Extension&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://powerbala.com/2012/01/01/extending-lightswitch-textbox-walk-through/"&gt;Extending LightSwitch TextBox : Walk-Through&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/86/Help-Desk-An-Advanced-Visual-Studio-LightSwitch-Application.aspx"&gt;Help Desk: An Advanced Visual Studio LightSwitch Application&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/78/Levels-of-Validation-and-Filtering-on-User-Membership.aspx"&gt;Levels of Validation and Filtering on User Membership&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://community.visual-basic.it/AlessandroEnglish/archive/2011/12/09/LightSwitch-increasing-the-client-side-timeout-in-code-VB.aspx"&gt;LightSwitch: increasing the client-side timeout in code (VB)&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://janvanderhaegen.wordpress.com/2011/12/22/lightswitch-and-the-mef-story/"&gt;LightSwitch and the MEF story&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://janvanderhaegen.wordpress.com/2011/12/19/metadata-driven-development-the-holy-grail-of-software-development/"&gt;Metadata driven development, the Holy Grail of software development&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.paulspatterson.com/technology/lightswitch/microsoft-lightswitch-championing-the-citizen-developer/"&gt;Microsoft LightSwitch – Championing the Citizen Developer&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.paulspatterson.com/technology/lightswitch/microsoft-lightswitch-code-project-lightswitch-star-contest/"&gt;Microsoft LightSwitch – Code Project LightSwitch Star Contest&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.paulspatterson.com/technology/lightswitch/microsoft-lightswitch-maintaining-a-primary-child-entity/"&gt;Microsoft LightSwitch – Maintaining a Primary Child Entity&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.paulspatterson.com/technology/lightswitch/lsmultiselectchecklist/"&gt;Microsoft LightSwitch – Multi Select Checklist&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.paulspatterson.com/technology/lightswitch/microsoft-lightswitch-simple-but-effective-application-defaults/"&gt;Microsoft LightSwitch – Simple but Effective Application Defaults&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/88/The-LightSwitch-JetPack-Theme.aspx"&gt;The LightSwitch JetPack Theme&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/91/Using-the-ComponentOne-FlexGrid-Control-in-Visual-Studio-LightSwitch.aspx"&gt;Using the ComponentOne FlexGrid Control in Visual Studio LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/89/Using-the-Infragistics-Reporting-with-OData-In-Visual-Studio-LightSwitch.aspx"&gt;Using the Infragistics Reporting with OData In Visual Studio LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/87/WindowsDevNews-com-A-Visual-Studio-LightSwitch-Application.aspx"&gt;WindowsDevNews.com: A Visual Studio LightSwitch Application&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;Samples (&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh204519"&gt;see all of them here&lt;/a&gt;):&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Background-Group-Layout-c272f8fb"&gt;Background Group Layout Extension - Source Code&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Extended-Text-Box-b8c7b911"&gt;Extended Text Box Extension - Source Code&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/How-to-Open-Properties-74f2cfaf"&gt;How to Open Properties Window for Default Project with Macro&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/LightSwitch-Image-Button-f9dda668"&gt;LightSwitch Image Button Extension – Walkthrough&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;LightSwitch Team Community Sites&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.facebook.com/vslightswitch" target="_blank"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 4px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="" align="left" src="http://badge.facebook.com/badge/151211271561073.1904.953280091.png" width="137" height="84" /&gt;&lt;/a&gt; The &lt;a href="http://www.facebook.com/vslightswitch" target="_blank"&gt;Visual Studio LightSwitch Facebook Page&lt;/a&gt; has been increasing in activity thanks to you all. Become a fan! Have fun and interact with us on our wall. Check out the cool stories and resources. &lt;/p&gt;  &lt;p&gt;Also here are some other places you can find the LightSwitch team:    &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/category/vslightswitch"&gt;LightSwitch MSDN Forums&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://msdn.com/lightswitch"&gt;LightSwitch Developer Center&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/lightswitch"&gt;LightSwitch Team Blog&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://twitter.com/#!/VSLightSwitch"&gt;LightSwitch on Twitter&lt;/a&gt; (@VSLightSwitch, #VisualStudio #LightSwitch) &lt;/p&gt;  &lt;h6&gt;Join Us!&lt;/h6&gt;  &lt;p&gt;The community has been using the hash tag #LightSwitch on twitter when posting stuff so it’s easier for me to catch it (although this is a common English word so you may end up with a few weird ones ;-)). &lt;a href="http://twitter.com/#!/search/realtime/%23LightSwitch"&gt;Join the conversation!&lt;/a&gt; And if I missed anything please add a comment to the bottom of this post and let us know!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10253299" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Community" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Community/" /><category term="Videos" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Videos/" /><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="Samples" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Samples/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Rollup" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Rollup/" /></entry><entry><title>Beginning LightSwitch Part 6: I Feel Pretty! Customizing the "Look and Feel" with Themes</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/21/beginning-lightswitch-part-6-i-feel-pretty-customizing-the-quot-look-and-feel-quot-with-themes.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/12/21/beginning-lightswitch-part-6-i-feel-pretty-customizing-the-quot-look-and-feel-quot-with-themes.aspx</id><published>2011-12-21T22:23:42Z</published><updated>2011-12-21T22:23:42Z</updated><content type="html">&lt;p&gt;Welcome to Part 6 of the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/tags/beginning+lightswitch+series/"&gt;Beginning LightSwitch series&lt;/a&gt;! In parts 1 thru 5 we built an Address Book application and learned all about the major building blocks of a &lt;a href="http://msdn.com/lightswitch"&gt;Visual Studio LightSwitch&lt;/a&gt; application -- &lt;em&gt;entities, relationships, screens, queries &lt;/em&gt;and &lt;em&gt;user permissions. &lt;/em&gt;If you missed them:     &lt;br /&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx"&gt;Part 1: What’s in a Table? Describing Your Data&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/08/beginning-lightswitch-part-2-feel-the-love-defining-data-relationships.aspx"&gt;Part 2: Feel the Love. Defining Data Relationships&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/14/beginning-lightswitch-part-3-screen-templates-which-one-do-i-choose.aspx"&gt;Part 3: Screen Templates, Which One Do I Choose?&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/15/beginning-lightswitch-part-4-too-much-information-sorting-and-filtering-data-with-queries.aspx"&gt;Part 4: Too much information! Sorting and Filtering Data with Queries&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/20/beginning-lightswitch-part-5-may-i-defining-user-permissions.aspx"&gt;Part 5: May I? Controlling Access with User Permissions&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In this post I want to talk about &lt;em&gt;themes. &lt;/em&gt;Themes allow you to change the colors, fonts and styles of all the visual elements in the user interface. Now that our Address Book application is complete, we’re almost ready to get this in front of real users. But before we do, it would be really nice to apply a different look-and-feel to our application in order to make it stand out above the rest. Visual Studio LightSwitch comes with only one theme out of the box, but you can download more. In fact, there are all kinds of &lt;em&gt;extensions &lt;/em&gt;you can download to enhance what LightSwitch can do out of the box, not just themes. &lt;/p&gt;  &lt;h3&gt;Visual Studio LightSwitch Extensibility&lt;/h3&gt;  &lt;p&gt;LightSwitch provides an entire extensibility framework so that professional developers can write extensions to enhance the LightSwitch development experience. Many third-party component vendors as well as the general community have released all sorts of extensions for LightSwitch. These include custom controls, business types, productivity libraries and designers, and of course themes. Check out some of the &lt;a href="http://www.microsoft.com/visualstudio/en-us/lightswitch/extensions" target="_blank"&gt;featured extensions&lt;/a&gt; from our partners. If you are a code-savvy, professional .NET developer with Visual Studio Professional or higher, then you can create your own extensions. For more information on creating extensions see the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh304488" target="_blank"&gt;Extensibility section&lt;/a&gt; of the &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;LightSwitch Developer Center&lt;/a&gt;. &lt;/p&gt;  &lt;h3&gt;Downloading and Enabling Extensions&lt;/h3&gt;  &lt;p&gt;Luckily, you don’t need to be a hardcore programmer to &lt;strong&gt;use &lt;/strong&gt;extensions. They are easy to find and install. Just open the Extension Manager from the Tools menu.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8551.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5430.image_5F00_thumb.png" width="611" height="236" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The Extension Manager will come up and display all your installed extensions. Select the “Online Gallery” tab to choose from all the LightSwitch extensions from the &lt;a href="http://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=VisualStudioVersion&amp;amp;f%5B0%5D.Value=VSLS&amp;amp;f%5B0%5D.Text=Visual%20Studio%20LightSwitch" target="_blank"&gt;Visual Studio Gallery&lt;/a&gt;. (Note: if you have Visual Studio Professional or higher and not just the LightSwitch edition installed, then you will need to filter the Extension Manager on “LightSwitch” to see those extensions.)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6406.image_5F00_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6011.image_5F00_thumb_5F00_1.png" width="713" height="492" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can also download these extensions directly from the &lt;a href="http://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=VisualStudioVersion&amp;amp;f%5B0%5D.Value=VSLS&amp;amp;f%5B0%5D.Text=Visual%20Studio%20LightSwitch" target="_blank"&gt;Visual Studio Gallery&lt;/a&gt;. Select the extension you want and click the download button to install. &lt;/p&gt;  &lt;p&gt;For our Address Book application I’m going to apply the LightSwitch Metro Theme which is one of the most popular extensions (at the time of this writing) so it’s right at the top. Once you install the extension, you’ll need to restart Visual Studio LightSwitch. After extensions are installed, you need to enable them on a per-project basis. Open the project properties by right-clicking on the project in the Solution Explorer and select “Properties”. Then select the “Extensions” tab to enable the extension. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7802.image_5F00_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2625.image_5F00_thumb_5F00_2.png" width="649" height="532" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For our Address Book application, enable the Metro Theme extension. Also notice that there is the “Microsoft LightSwitch Extensions” also in this list which is always enabled and used in new projects. This is an extension that is included with the LightSwitch install and contains the business types&lt;em&gt; Email Address&lt;/em&gt;, &lt;em&gt;Phone Number&lt;/em&gt;, &lt;em&gt;Money &lt;/em&gt;and &lt;em&gt;Image &lt;/em&gt;that you can use when defining your data entities like we did in &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx" target="_blank"&gt;Part 1&lt;/a&gt;. You should never have to disable these. &lt;/p&gt;  &lt;h3&gt;Applying a Theme&lt;/h3&gt;  &lt;p&gt;Now that the theme extension is installed and enabled, you can apply the theme by selecting the “General Properties” tab and then choosing the LightSwitch Metro Theme.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1541.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4353.image_5F00_thumb_5F00_3.png" width="583" height="245" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then just build and run (F5) the application to see how it looks! &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2625.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7802.image_5F00_thumb_5F00_4.png" width="720" height="490" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For more information on the Metro Theme extension (and source code) see the &lt;a href="http://code.msdn.microsoft.com/LightSwitch-Metro-Theme-b1bfce24" target="_blank"&gt;&lt;em&gt;LightSwitch Metro Theme Extension Sample&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;Some More Cool LightSwitch Themes&lt;/h3&gt;    &lt;p&gt;&lt;img style="margin: 0px 9px 0px 0px; display: inline; float: left" title="ShinyThemes-300x90" alt="" align="left" src="http://www.paulspatterson.com/wp-content/uploads/2011/11/ShinyThemes-300x90.png" width="300" height="90" /&gt;Besides the Metro Theme, there are a lot of other nice looking themes available, some for free and some for a small fee. If you open the Extension Manager to the Online Gallery tab and enter the search term “theme” you will see a long list of them. Here are the top 5 most popular on the gallery (at the time of this writing):&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/e56d790d-ceea-43e6-8ce2-06d274ef7654"&gt;LightSwitch Metro Theme &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/5617c9a0-c8e9-4a63-b3fc-b0356dad430f"&gt;Spursoft LightSwitch Extensions&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/654f745f-eba9-45f7-ac1e-d23da173345a"&gt;Themes by Delordson (LightSwitchExtras.com) &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/10bc78be-f465-4b38-9b61-d66aa0b137e4"&gt;Luminous Themes &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/032a1cd3-9402-49da-927b-095d8476cc7c"&gt;VS Dark Blue Theme &lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Also check out &lt;a href="http://www.paulspatterson.com/microsoft-lightswitch-theme-resources/" target="_blank"&gt;Paul Patterson’s “Uber Theme Resource”&lt;/a&gt; which provides more screenshots and reviews of all the themes on the gallery!&lt;/p&gt;  &lt;h3&gt;Wrap Up&lt;/h3&gt;  &lt;p&gt;As you can see it’s easy to download and enable themes in Visual Studio LightSwitch in order to change the look-and-feel of your business applications. LightSwitch provides an entire extensibility model that not only allows the community to create themes, but all kinds of extensions that enhance the LightSwitch development experience that you can take advantage of. If you’re a code-savvy developer that wants to create your own themes, head to the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh304488" target="_blank"&gt;Extensibility section&lt;/a&gt; of the &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;LightSwitch Developer Center&lt;/a&gt; to get set up and then read this walkthrough &lt;a href="http://msdn.microsoft.com/en-us/library/hh290139.aspx"&gt;&lt;em&gt;Creating a Theme Extension&lt;/em&gt;&lt;/a&gt;. &lt;/p&gt;    &lt;p&gt;Well that wraps up what I planned for the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/tags/beginning+lightswitch+series/" target="_blank"&gt;Beginning LightSwitch Series&lt;/a&gt;! I hope you enjoyed it and I hope it has helped you get started building your own applications with Visual Studio LightSwitch. For more LightSwitch training please see the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857.aspx" target="_blank"&gt;&lt;u&gt;Learn &lt;/u&gt;section of the LightSwitch Developer Center&lt;/a&gt;. In particular, I recommend going through my &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823" target="_blank"&gt;“How Do I” videos&lt;/a&gt; next.&lt;/p&gt;  &lt;p&gt;Now I’m going to go enjoy some well-earned Christmas vacation. I’ll be back in a couple weeks. Happy Holidays LightSwitch-ers! Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250138" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Beginning LightSwitch Series" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Beginning+LightSwitch+Series/" /><category term="Extensibility" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Extensibility/" /></entry><entry><title>Beginning LightSwitch Part 5: May I? Controlling Access with User Permissions</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/20/beginning-lightswitch-part-5-may-i-defining-user-permissions.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/12/20/beginning-lightswitch-part-5-may-i-defining-user-permissions.aspx</id><published>2011-12-20T21:11:00Z</published><updated>2011-12-20T21:11:00Z</updated><content type="html">&lt;p&gt;Welcome to Part 5 of the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/tags/beginning+lightswitch+series/"&gt;Beginning LightSwitch series&lt;/a&gt;! In parts 1 thru 4 we learned about &lt;em&gt;entities, relationships, screens &lt;/em&gt;and &lt;em&gt;queries &lt;/em&gt;in &lt;a href="http://msdn.com/lightswitch"&gt;Visual Studio LightSwitch&lt;/a&gt;. If you missed them: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx"&gt;Part 1: What’s in a Table? Describing Your Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/08/beginning-lightswitch-part-2-feel-the-love-defining-data-relationships.aspx"&gt;Part 2: Feel the Love. Defining Data Relationships&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/14/beginning-lightswitch-part-3-screen-templates-which-one-do-i-choose.aspx"&gt;Part 3: Screen Templates, Which One Do I Choose?&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/15/beginning-lightswitch-part-4-too-much-information-sorting-and-filtering-data-with-queries.aspx"&gt;Part 4: Too much information! Sorting and Filtering Data with Queries&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In this post I want to talk about &lt;em&gt;user permissions, &lt;/em&gt;also known as &lt;strong&gt;Access Control&lt;/strong&gt;&lt;em&gt;. &lt;/em&gt;In most business applications we need to limit what resources users can access in the system, usually because of different job function or role. For instance, only system administrators can add new users to the system. Certain data and screens in the application may be sensitive and should be restricted unless that user has rights to that part of the system. LightSwitch makes it easy to define user permissions and provides hooks on entities, screens and queries that allow you to check these permissions. &lt;/p&gt;  &lt;p&gt;For a video demonstration on how to set up user permissions see: &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg278959"&gt;&lt;em&gt;How Do I: Set Up Security to Control User Access to Parts of a Visual Studio LightSwitch Application?&lt;/em&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;Authentication &amp;amp; Authorization&lt;/h3&gt;  &lt;p&gt;There are two pieces of information LightSwitch applications need in order to determine which users have rights to what parts of the system. First, the system needs to verify the user accessing the application. This is called &lt;em&gt;Authentication. &lt;/em&gt;In other words: “Prove you are who you say you are.” There are two supported types of authentication in LightSwitch; &lt;em&gt;Windows&lt;/em&gt; and &lt;em&gt;Forms. &lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Windows authentication means that the application trusts the user based on their Windows credentials. So once a user successfully logs into their Windows desktop, those credentials are automatically passed to the LightSwitch application. Forms authentication means that the application requests a username &amp;amp; password of its own, completely independent of any other credentials. So when you choose to use Forms authentication a login screen is presented to the user and they must type their username and password every time they want to access the application. &lt;/p&gt;  &lt;p&gt;Once a user is authenticated, the application can determine access to parts of the system by reading their user permissions. This is called &lt;em&gt;Authorization&lt;/em&gt;. In other words: “Now that I know who you are, here’s what you can do in the system.” &lt;/p&gt;  &lt;h3&gt;Setting Up User Permissions&lt;/h3&gt;  &lt;p&gt;It all starts on the Access Control tab of the Project Properties. To open it, right-click on the name of your project in the Solution Explorer and select “Properties” from the menu. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0456.image_5F00_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5611.image_5F00_thumb_5F00_1.png" width="576" height="440" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Then select the Access Control tab to specify the type of authentication you want to employ as well as what user permissions you want to define. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5621.image_5F00_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8272.image_5F00_thumb_5F00_2.png" width="748" height="325" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;By default, the application doesn’t have authentication enabled so here is where you select the type of authentication you want to use. &lt;/p&gt;  &lt;p&gt;Using Forms authentication means you will be storing usernames and encrypted passwords inside the LightSwitch database. This type of authentication is appropriate for internet-based applications where users are not on the same network and you need to support other operating systems besides Windows. &lt;/p&gt;  &lt;p&gt;Using Windows authentication is appropriate if all your users are on the same network/domain or workgroup, like in the case of an internal line-of-business application. This means that no passwords are stored by your LightSwitch application. Instead the Windows logon credentials are used and passed automatically to the application. This is a more secure and convenient option if you can use it. In this case you can also choose whether you want to set up specific users and roles or whether any authenticated user has access to the application. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4555.image_5F00_14.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1030.image_5F00_thumb.png" width="388" height="152" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The best way to think of the two options for Windows authentication are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Give special permissions and roles to the Windows users that I administer within the application. (This is always on if you have selected Windows authentication) &lt;/li&gt;    &lt;li&gt;ALSO, let &lt;em&gt;any &lt;/em&gt;Windows user access the unprotected parts of my application &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Next you define user permissions that you check in code in order to access resources (we’ll work through an example next). There is always a SecurityAdministration permission defined for you that is used by LightSwitch once you deploy the application. When you deploy, LightSwitch will create a single user with this permission which gives them access to the screens necessary to define the rest of the users and roles in the system. However, while debugging your application, LightSwitch doesn’t make you log in because this would be tedious to do every time you built and ran (F5) the application. So instead you can use the “Granted for debug” checkbox to indicate which sets of permissions should be turned on/off in the debug session. &lt;/p&gt;  &lt;p&gt;Let’s walk through a concrete example by implementing some security in our Address Book (Contact Manager) application we’ve been building in this series. &lt;/p&gt;  &lt;h3&gt;Checking User Permissions in the Address Book Application&lt;/h3&gt;  &lt;p&gt;Let’s start by selecting an authentication scheme. Since this application will be used by a small business to manage all their contacts, I’ll choose Windows authentication. I’ll also select “Allow any authenticated Windows user” into the system so that everyone in the company can search for and edit contacts by default. However, in order to add or delete contacts, users will need special permissions to do that. &lt;/p&gt;  &lt;p&gt;So we need to create two new permissions. You can name the permissions whatever you want. You only see the name in code. When the system administrator sets up users and roles later, they will see the Display Name on the screen so be descriptive there. So add two permissions; CanAddContacts and CanDeleteContacts.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5127.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0336.image_5F00_thumb_5F00_3.png" width="717" height="288" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next, leave the “Granted for debug” unchecked for both of those permissions so that we can test that they are working. When you leave this unchecked, the permission will not be granted. This allows us to easily test combinations of permissions while debugging. In order to see the Users and Roles screens while debugging you can enable it for SecurityAdministration. Now that we have these permissions set up here, we need to check them in code. As I mentioned, LightSwitch provides method hooks for you so you can write code when you need for all sorts of custom validation and business rules, including access control. &lt;/p&gt;  &lt;p&gt;For more information on writing code in LightSwitch see the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg697783"&gt;&lt;strong&gt;&lt;em&gt;Working with Code&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; topic on the &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;LightSwitch Developer Center&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;For more information on writing custom business rules see: &lt;em&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/11/11/common-validation-rules-in-lightswitch-business-applications.aspx" target="_blank"&gt;Common Validation Rules in LightSwitch Business Applications&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;So in order to implement the security, we need to write a couple lines of code to check these permissions. LightSwitch provides access control methods on entities, screens and queries. To access these methods, drop down the “Write code” button on the top right of any designer and you will see an “Access Control Methods” section in the list. When you want to restrict viewing (reading), inserting (adding), editing or deleting entities, open the entity in the Data Designer and drop down the “Write code” button and select the appropriate access control method.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0434.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5545.image_5F00_thumb_5F00_4.png" width="277" height="431" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For this application, select the Contacts_CanDelete method and this will open the code editor to that method stub. All you need to do is write one line of code (in &lt;strong&gt;bold&lt;/strong&gt; below) to check the CanDeleteContacts permission you set up:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Namespace &lt;/span&gt;LightSwitchApplication

    &lt;span style="color: blue"&gt;Public Class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ApplicationDataService

        &lt;/span&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Contacts_CanDelete(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;result &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;)
            &lt;span style="color: green"&gt;'Add this one line of code to verify the user has permission to delete contacts:
&lt;strong&gt;            &lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;result = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.Application.User.HasPermission(&lt;span style="color: #2b91af"&gt;Permissions&lt;/span&gt;.CanDeleteContacts)&lt;/strong&gt;

        &lt;span style="color: blue"&gt;End Sub
    End Class

End Namespace
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Note: This code is Visual Basic. If you chose C# as your programming language when you created the ContactManager project in &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx" target="_blank"&gt;Part 1&lt;/a&gt;, you will need to write the code like this: result = &lt;strong&gt;this&lt;/strong&gt;.Application.User.HasPermission(Permissions.CanDeleteContacts)&lt;strong&gt;;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now go back to the “Write Code” button on the designer and select Contacts_CanInsert and then similarly write the following line of code (in bold) to check the CanAddContacts permission:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Namespace &lt;/span&gt;LightSwitchApplication

    &lt;span style="color: blue"&gt;Public Class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ApplicationDataService

        &lt;/span&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Contacts_CanDelete(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;result &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;)
            &lt;span style="color: green"&gt;'Add this one line of code to verify the user has permission to delete contacts:
            &lt;/span&gt;result = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.Application.User.HasPermission(&lt;span style="color: #2b91af"&gt;Permissions&lt;/span&gt;.CanDeleteContacts)

        &lt;span style="color: blue"&gt;End Sub

        Private Sub &lt;/span&gt;Contacts_CanInsert(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;result &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;)
            &lt;span style="color: green"&gt;'Add this one line of code to verify the user has permission to add contacts:
           &lt;strong&gt; &lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;result = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.Application.User.HasPermission(&lt;span style="color: #2b91af"&gt;Permissions&lt;/span&gt;.CanAddContacts)&lt;/strong&gt;
        &lt;span style="color: blue"&gt;End Sub
    End Class

End Namespace
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You may be wondering why we are checking these permissions in the entity instead of the screens. Checking permissions in the entity guarantees that no matter what screen the user is working with, the data actions are protected. It’s best practice remember to secure your entities first if you need to implement user permissions in your application. However, our application also has a “Create New Contact” screen and we don’t want to show this to the user on the menu if they do not have permission to add contacts to the system. If we forget to hide this screen from the menu, then the user would be able to open it and fill it out with data. However, when they click Save the Contacts_CanInsert method above will run and prevent the actual data from saving. &lt;/p&gt;

&lt;p&gt;So in order to hide this screen from the navigation menu, we need to add one more check. Double-click the CreateNewContact screen in the Solution Explorer to open the Screen Designer. Drop down the “Write Code” button on the top right and you will see the one Access Control method available to you for screens:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3566.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5226.image_5F00_thumb_5F00_5.png" width="257" height="266" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the CreateNewContact_CanRun method and then write the following line of code (in bold):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Namespace &lt;/span&gt;LightSwitchApplication

    &lt;span style="color: blue"&gt;Public Class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Application

        &lt;/span&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;CreateNewContact_CanRun(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;result &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;)
            &lt;span style="color: green"&gt;'Add this one line of code to verify the user has permission to run the screen:
           &lt;strong&gt; &lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;result = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.User.HasPermission(&lt;span style="color: #2b91af"&gt;Permissions&lt;/span&gt;.CanAddContacts)&lt;/strong&gt;

        &lt;span style="color: blue"&gt;End Sub
    End Class

End Namespace

&lt;/span&gt;&lt;/pre&gt;

&lt;h3&gt;Run it!&lt;/h3&gt;

&lt;p&gt;Now we are ready to test the application so build and run by hitting &lt;strong&gt;F5&lt;/strong&gt;. Because we didn’t grant the CanAddContacts and CanDeleteContacts permissions for debug you will notice first that the CreateNewContact screen is not showing up on the menu. The first screen that displays is the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/15/beginning-lightswitch-part-4-too-much-information-sorting-and-filtering-data-with-queries.aspx" target="_blank"&gt;custom search screen we created in Part 4&lt;/a&gt;. If you click on a contact then the details screen will open which allows the user to edit that contact’s information. In order to see if we are restricted from deleting or adding new contacts let’s make a small change to the search screen. While the search screen is open click the “Design Screen” button at the top right to open the screen customization mode.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8688.image_5F00_16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7774.image_5F00_thumb_5F00_6.png" width="664" height="467" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the content tree on the left, expand the command bar under the Data Grid and add two commands; DeleteSelected and AddAndEditNew.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7271.image_5F00_18.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4062.image_5F00_thumb_5F00_7.png" width="326" height="360" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click Save (ctrl+shift+S) to save and exit customization mode and notice that the commands are disabled. Since we do not have permission to add or delete contacts this behavior is correct. Also since we are &lt;strong&gt;checking these permissions at the entity level all screen commands behave appropriately with no additional code necessary. &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8764.image_5F00_20.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1423.image_5F00_thumb_5F00_8.png" width="336" height="137" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you go back to your project properties Access Control tab you can check off combinations of permissions you want to test and you will see all commands enable/disable appropriately. &lt;/p&gt;

&lt;h3&gt;Users &amp;amp; Roles Screens&lt;/h3&gt;

&lt;p&gt;Before we wrap up I want to quickly walk through the Users and Roles screens. When you enable the SecurityAdministration permission for debugging, these screens are available on the menu. However, keep in mind that the data you put into these screens isn’t used at debug time. It isn’t later until you deploy the application when these screens are used. So putting data into these screens is for demonstration purposes only. When your application is deployed the first time, LightSwitch will ask you for an administrator username &amp;amp; password that it deploys into the users table and grants the SecurityAdministration permission. That administrator can then enter the rest of the users into the system. &lt;/p&gt;

&lt;p&gt;First you define roles and add the permissions you defined to that role using the Roles Screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6201.image_5F00_22.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2313.image_5F00_thumb_5F00_9.png" width="667" height="517" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then you can add new users using the Users Screen and assign them the appropriate Roles.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3566.image_5F00_24.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3173.image_5F00_thumb_5F00_10.png" width="670" height="516" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Wrap Up&lt;/h3&gt;

&lt;p&gt;As you can see defining and checking user permissions in Visual Studio LightSwitch is a simple but important task. Access control is a very common requirement in professional business applications and LightSwitch provides an easy to use framework for locking down all parts of the application through method hooks on entities, screens and queries. Once you deploy your application, the system administrator can start setting up users and roles to control access to the secure parts of your application. &lt;/p&gt;

&lt;p&gt;For more information on user permissions and deploying applications see &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg697762" target="_blank"&gt;Working with User Permissions&lt;/a&gt; &lt;/em&gt;and &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg697766"&gt;&lt;strong&gt;&lt;em&gt;Deploying LightSwitch Applications&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; topics on the &lt;a href="http://msdn.com/lightswitch"&gt;LightSwitch Developer Center&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;In the next post we’ll look at &lt;em&gt;themes &lt;/em&gt;and how to change the look and feel of your application by installing LightSwitch extensions. We’ll look at what’s available for free as well as some inexpensive ones that really look great. Until next time! &lt;/p&gt;

&lt;p&gt;Enjoy! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Go to next article –&amp;gt; &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/21/beginning-lightswitch-part-6-i-feel-pretty-customizing-the-quot-look-and-feel-quot-with-themes.aspx"&gt;I Feel Pretty! Customizing the &amp;quot;Look and Feel&amp;quot; with Themes&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249744" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Security" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Security/" /><category term="Beginning LightSwitch Series" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Beginning+LightSwitch+Series/" /></entry><entry><title>Beginning LightSwitch Part 4: Too much information! Sorting and Filtering Data with Queries</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/15/beginning-lightswitch-part-4-too-much-information-sorting-and-filtering-data-with-queries.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/12/15/beginning-lightswitch-part-4-too-much-information-sorting-and-filtering-data-with-queries.aspx</id><published>2011-12-15T20:42:00Z</published><updated>2011-12-15T20:42:00Z</updated><content type="html">&lt;p&gt;Welcome to Part 4 of the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/tags/beginning+lightswitch+series/"&gt;Beginning LightSwitch series&lt;/a&gt;! In part 1, 2 and 3 we learned about &lt;em&gt;entities, relationships &lt;/em&gt;and &lt;em&gt;screens &lt;/em&gt;in &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;Visual Studio LightSwitch&lt;/a&gt;. If you missed them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx"&gt;Part 1: What&amp;rsquo;s in a Table? Describing Your Data&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/08/beginning-lightswitch-part-2-feel-the-love-defining-data-relationships.aspx"&gt;Part 2: Feel the Love. Defining Data Relationships&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/14/beginning-lightswitch-part-3-screen-templates-which-one-do-i-choose.aspx"&gt;Part 3: Screen Templates, Which One Do I Choose?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this post I want to talk about &lt;em&gt;queries&lt;/em&gt;&lt;em&gt;. &lt;/em&gt;In real life a query is just a question. But when we talk about queries in the context of databases, we are referring to a query language used to request particular subsets of data from our database. You use queries to help users find the information they are looking for and focus them on the data needed for the task at hand. As your data grows, queries become extremely necessary to keep your application productive for users. Instead of searching an entire table one page at a time for the information you want, you use queries to narrow down the results to a manageable list.&amp;nbsp; For example, if you want to know how many contacts live in California, you create a query that looks at the list of Contacts and checks the State in their Address.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve been following this article series, you actually already know how to execute queries in LightSwitch. In part 3 we built a Search Data Screen. This screen has a built-in search feature that allows users to type in search terms and return rows where any string field matches that term. In this post I want to show you how you can define your own queries using the Query Designer and how you can use them on screens.&lt;/p&gt;
&lt;h3&gt;The LightSwitch Query Designer&lt;/h3&gt;
&lt;p&gt;The Query Designer helps you construct queries sent to the backend data source in order to retrieve the entities you want. You use the designer to create filter conditions and specify sorting options. A query in LightSwitch is based on an entity in your data model (for example, a Contact entity). A query can also be based on other queries so they can be built-up easily. For instance, if you define a query called SortedContacts that sorts Contacts by their LastName property, you can then use this query as the source of other queries that return Contacts. This avoids having to repeat filter and/or sort conditions that you may want to apply on every query.&lt;/p&gt;
&lt;p&gt;For a tour of the Query Designer, see &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee256728.aspx" target="_blank"&gt;Queries: Retrieving Information from a Data Source&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;For a video demonstration on how to use the Query Designer, see: &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff949857"&gt;&lt;em&gt;How Do I: Sort and Filter Data on a Screen in a LightSwitch Application?&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Creating a &amp;ldquo;SortedContacts&amp;rdquo; Query&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s walk through some concrete examples of creating queries in LightSwitch using the Contact Manager Address Book application we&amp;rsquo;ve been building. In part 3 we built a Search Data Screen for our Contacts, but if you notice the Contacts are not sorted when the screen is initially displayed. The user must click on the desired grid column to apply a sort manually. Once the user changes the sort order LightSwitch will remember that on a per-user basis, but we should really be sorting the Contacts for them when the Search screen is displayed the first time.&lt;/p&gt;
&lt;p&gt;To create a query, in the Solution Explorer right-click on the entity you want to base it on (in our case Contacts) and choose &amp;ldquo;Add Query&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5282.image_5F00_4.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6378.image_5F00_thumb_5F00_1.png" width="279" height="279" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The Query Designer will open and the first thing you do is name your query. We&amp;rsquo;ll name ours &amp;ldquo;SortedContacts&amp;rdquo;. Once you do this, you will see the query listed under the entity in the Solution Explorer.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1513.image_5F00_10.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0116.image_5F00_thumb_5F00_4.png" width="713" height="516" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Next we need to define the sort order so click &amp;ldquo;&lt;em&gt;+Add Sort&lt;/em&gt;&amp;rdquo; in the Sort section of the designer then select the LastName property from the drop down. Click &amp;ldquo;&lt;em&gt;+Add Sort&lt;/em&gt;&amp;rdquo; again and this time select the FirstName property. Leave the order Ascending for both.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7776.image_5F00_12.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3250.image_5F00_thumb_5F00_5.png" width="340" height="281" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Before we jump into Filter conditions and Parameters, let&amp;rsquo;s see how we can use this simple query on our Search Screen. It&amp;rsquo;s actually easier in this case to re-create the Search Screen we created in Part 3 because we didn&amp;rsquo;t make any modifications to the layout. So in the Solution Explorer select the SearchContacts screen and delete it. Then right-click on the Screens node and select &amp;ldquo;Add Screen&amp;hellip;&amp;rdquo; to open the Add New Screen dialog.&lt;/p&gt;
&lt;p&gt;Select the Search Data Screen template then for the Screen Data you will see the SortedCOntacts query. Choose that then click OK.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2664.image_5F00_14.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1106.image_5F00_thumb_5F00_6.png" width="726" height="516" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hit &lt;strong&gt;F5&lt;/strong&gt; to build and run the application and notice this time the contacts are sorted in alphabetical order immediately.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8546.image_5F00_16.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1425.image_5F00_thumb_5F00_7.png" width="643" height="262" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Defining Filter Conditions and Parameters&lt;/h3&gt;
&lt;p&gt;Our Search Screen is in better shape now but what if we wanted to allow the user to find contacts who&amp;rsquo;s birth date falls within a specific range? Out of the box, LightSwitch will automatically search across all &lt;strong&gt;String &lt;/strong&gt;properties on an entity but not Dates. Therefore, in order to allow the user the ability to search within a birth date range, we need to define our own query.&lt;/p&gt;
&lt;p&gt;So let&amp;rsquo;s create a query that filters by date range but this time we will specify the &lt;em&gt;Source &lt;/em&gt;of the query be the SortedContacts query. Right-click on the Contacts entity and choose &amp;ldquo;Add Query&amp;rdquo; to open the Query Designer again. Name the query &amp;ldquo;ContactsByBirthDate&amp;rdquo; and then select &amp;ldquo;SortedContacts&amp;rdquo; in the Source drop down on the top right of the designer.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6708.image_5F00_18.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4743.image_5F00_thumb_5F00_8.png" width="752" height="132" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now the query is sorted but we need to add a filter condition. Defining filter conditions can take some practice (like designing a good data model) but LightSwitch tries to make it as easy as possible while still remaining powerful. You can specify fairly complex conditions and groupings in your filter, however the one we need to define isn&amp;rsquo;t too complex. When you need to find records within a range of values you will need 2 conditions. Once that checks records fall &amp;ldquo;above&amp;rdquo; the minimum value and one that checks records fall &amp;ldquo;below&amp;rdquo; the maximum value.&lt;/p&gt;
&lt;p&gt;So in the Query Designer, click &lt;em&gt;&amp;ldquo;+ Add Filter&amp;rdquo; &lt;/em&gt;and specify the condition like so:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Where&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3731.image_5F00_26.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5710.image_5F00_thumb_5F00_12.png" width="468" height="140" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;the &lt;strong&gt;BirthDate&lt;/strong&gt; property&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1184.image_5F00_28.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0523.image_5F00_thumb_5F00_13.png" width="465" height="200" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;is greater than or equal to&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3568.image_5F00_30.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3175.image_5F00_thumb_5F00_14.png" width="470" height="323" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;a &lt;strong&gt;parameter&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3162.image_5F00_32.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8546.image_5F00_thumb_5F00_15.png" width="472" height="186" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then select &amp;ldquo;Add New&amp;rdquo; to add a new parameter.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1425.image_5F00_34.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3175.image_5F00_thumb_5F00_16.png" width="471" height="127" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The parameter&amp;rsquo;s name will default to &amp;ldquo;BirthDate&amp;rdquo; so change it to &lt;strong&gt;MinimumBirthDate&lt;/strong&gt; down in the Parameters section.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3162.image_5F00_36.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8546.image_5F00_thumb_5F00_17.png" width="469" height="271" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Similarly, add the filter condition for &amp;ldquo;&lt;strong&gt;Where&lt;/strong&gt; the &lt;strong&gt;BirthDate&lt;/strong&gt; property&lt;strong&gt; is less than or equal to&lt;/strong&gt; a &lt;strong&gt;new parameter&lt;/strong&gt; called &lt;strong&gt;MaximumBirthDate&lt;/strong&gt;&amp;rdquo;. The Query Designer should now look like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8867.image_5F00_38.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5241.image_5F00_thumb_5F00_18.png" width="465" height="297" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;One last thing we want to think about with respect to parameters is whether they should be required or not. Meaning &lt;strong&gt;must &lt;/strong&gt;the user fill out the filter criteria parameters in order to execute the query? In this case, I don&amp;rsquo;t want to force the user to enter either one so we want to make them optional. You do that by selecting the parameter and checking &amp;ldquo;Is Optional&amp;rdquo; in the properties window.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0844.image_5F00_42.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8877.image_5F00_thumb_5F00_20.png" width="751" height="415" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Okay now let&amp;rsquo;s use this query for our Search Screen. In the Solution Explorer select the SearchSortedContacts screen and delete it. Then right-click on the Screens node and select &amp;ldquo;Add Screen&amp;hellip;&amp;rdquo; to open the Add New Screen dialog again. Select the Search Data Screen template and for the Screen Data select the ContactsByBirthDate query and click OK.&lt;/p&gt;
&lt;p&gt;Hit &lt;strong&gt;F5&lt;/strong&gt; to build and run the application. Notice the contacts are still sorted in alphabetical order on our search screen but you see additional fields at the top of the screen that let us specify the birth date range. LightSwitch sees that our query specified parameters so when we used it as the basis of the screen, the correct controls were automatically generated for us! And since both of these parameters are optional, users can enter none, one, or both dates and the query will automatically execute correctly based on that criteria.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0042.image_5F00_44.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2021.image_5F00_thumb_5F00_21.png" width="737" height="247" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you can see using queries with parameters like this allows you to perform much more specialized searches than what is provided by default. When using queries as the basis of Screen Data, LightSwitch will automatically look at the query&amp;rsquo;s parameters and create the corresponding screen parameters and controls which saves you time.&lt;/p&gt;
&lt;p&gt;For more information on creating custom search screens, see: &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2010/11/09/creating-a-custom-search-screen-in-visual-studio-lightswitch.aspx"&gt;&lt;em&gt;Creating a Custom Search Screen in Visual Studio LightSwitch&lt;/em&gt;&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2010/11/22/how-to-create-a-screen-with-multiple-search-parameters-in-lightswitch.aspx" target="_blank"&gt;How to Create a Screen with Multiple Search Parameters in LightSwitch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For a video demonstration, see: &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh499661.aspx"&gt;&lt;em&gt;How Do I: Create Custom Search Screens in LightSwitch?&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Querying Related Entities&lt;/h3&gt;
&lt;p&gt;Before we wrap this up I want to touch on one more type of query. What if we wanted to allow the user to search Contacts by phone number? If you recall our data is modeled so that Contacts can have many Phone Numbers so they are stored in a separate related table. In order to query these, we need to base the query on the PhoneNumber entity, not Contact.&lt;/p&gt;
&lt;p&gt;So right-click on the PhoneNumbers entity in the Solution Explorer and select &amp;ldquo;Add Query&amp;rdquo;. I&amp;rsquo;ll name it ContactsByPhone. Besides searching on the PhoneNumber I also want to allow users to search on the Contact&amp;rsquo;s LastName and FirstName. This is easy to do because the Query Designer will allow you to create conditions that filter on related parent tables, in this case the Contact. When you select the property, you can expand the Contact node and get at all the properties.&lt;/p&gt;
&lt;p&gt;So in the Query Designer, click &lt;em&gt;&amp;ldquo;+ Add Filter&amp;rdquo; &lt;/em&gt;and specify the condition like so:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Where &lt;/strong&gt;the &lt;strong&gt;Contact&amp;rsquo;s LastName &lt;/strong&gt;property&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4604.image_5F00_53.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6758.image_5F00_thumb_5F00_22.png" width="453" height="285" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;contains &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0385.image_5F00_55.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7725.image_5F00_thumb_5F00_23.png" width="490" height="322" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;a &lt;strong&gt;parameter &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7823.image_5F00_57.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2548.image_5F00_thumb_5F00_24.png" width="489" height="251" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then select &amp;ldquo;Add New&amp;rdquo; to add a new parameter.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6232.image_5F00_59.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6330.image_5F00_thumb_5F00_25.png" width="490" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The parameter&amp;rsquo;s name will default to &amp;ldquo;LastName&amp;rdquo; so change it to &lt;strong&gt;SearchTerm &lt;/strong&gt;down in the Parameters section and make it optional by checking &amp;ldquo;Is Optional&amp;rdquo; in the properties window.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3603.image_5F00_61.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7713.image_5F00_thumb_5F00_26.png" width="525" height="268" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re going to use the same parameter for the rest of our conditions. This will allow the user to type their search criteria in one textbox and the query will search across all three fields for a match. So the next filter condition will be:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Or &lt;/strong&gt;the &lt;strong&gt;Contact&amp;rsquo;s FirstName &lt;/strong&gt;property &lt;strong&gt;contains &lt;/strong&gt;the &lt;strong&gt;parameter &lt;/strong&gt;of &lt;strong&gt;SearchTerm&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6242.image_5F00_63.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5340.image_5F00_thumb_5F00_27.png" width="532" height="294" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And finally add the last filter condition:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Or &lt;/strong&gt;the &lt;strong&gt;Phone &lt;/strong&gt;property &lt;strong&gt;contains &lt;/strong&gt;the &lt;strong&gt;parameter &lt;/strong&gt;of &lt;strong&gt;SearchTerm&lt;/strong&gt;. I&amp;rsquo;ll also add a Sort on the PhoneNumber Ascending. The Query Designer should now look like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0385.image_5F00_65.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8473.image_5F00_thumb_5F00_28.png" width="525" height="347" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now it&amp;rsquo;s time to create a Search Screen for this query. Instead of deleting the other Search screen that filters by birth date range, I&amp;rsquo;m going to create another new search screen for this query. Another option would be to add the previous date range condition to this query, which would create a more complex query but would allow us to have one search screen that does it all. For this example let&amp;rsquo;s keep it simple, but here&amp;rsquo;s a hint on how you would construct the query by using a group:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1055.image_5F00_75.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5153.image_5F00_thumb_5F00_33.png" width="552" height="524" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For more information on writing complex queries see: &lt;a href="http://msdn.microsoft.com/library/ee256728.aspx"&gt;&lt;em&gt;Queries: Retrieving Information from a Data Source &lt;/em&gt;&lt;/a&gt;and &lt;em&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/04/18/how-to-create-composed-and-scalar-queries-ravi-eda.aspx" target="_blank"&gt;How to Create Composed and Scalar Queries&lt;/a&gt; &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So to add the new Search Screen right-click on the Screens node again and select &amp;ldquo;Add Screen&amp;hellip;&amp;rdquo; to open the Add New Screen dialog. Select the Search Data Screen template and for the Screen Data select the ContactsByPhone query this time and click OK.&lt;/p&gt;
&lt;p&gt;Now before we run this I want to make a small change to the screen. The default behavior of a search screen is to make the first column a link that opens the Details screen for that record. Since we had to base our query on the PhoneNumber entity, LightSwitch will make the Phone property a link and not the Contact. So in the Screen Designer we need to make a small change. Select the Phone in the content tree and in the properties window uncheck &amp;ldquo;Show as Link&amp;rdquo;. Then select the Contact and check &amp;ldquo;Show as Link&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4760.image_5F00_69.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0878.image_5F00_thumb_5F00_30.png" width="763" height="470" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Also change Display Name in the properties window for the PhoneNumberSearchTerm textbox to &amp;ldquo;Phone Number or Name&amp;rdquo; to make it more clear to the user what they are filtering on. And while we&amp;rsquo;re at it, we should disable the default search box by selecting the ContactsByPhone query on the left-hand side and unchecking &amp;ldquo;Supports search&amp;rdquo; in the properties window. This isn&amp;rsquo;t necessary since we are providing more search functionality with our own query.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3187.image_5F00_71.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0066.image_5F00_thumb_5F00_31.png" width="768" height="472" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Okay hit &lt;strong&gt;F5 &lt;/strong&gt;and let&amp;rsquo;s see what we get. Open the &amp;ldquo;Search Contact By Phone&amp;rdquo; Search screen from the navigation menu and now users can search for contacts by name or by phone number. When you click on the Contact link, the Details screen we created in part 3 will open automatically.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5340.image_5F00_73.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0385.image_5F00_thumb_5F00_32.png" width="595" height="194" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Wrap Up&lt;/h3&gt;
&lt;p&gt;As you can see queries help narrow down the amount of data to just the information users need to get the task done. LightSwitch provides a simple, easy-to-use Query Designer that lets you base queries on entities as well as other queries. And the LightSwitch Screen Designer does all the heavy lifting for you when you base a screen on a query that uses parameters.&lt;/p&gt;
&lt;p&gt;Writing good queries takes practice so I encourage you to work through the resources provided in the &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg685457" target="_blank"&gt;Working with Queries&lt;/a&gt; &lt;/em&gt;topic on the &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;LightSwitch Developer Center&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the next post we&amp;rsquo;ll look at &lt;em&gt;user permissions &lt;/em&gt;and you will see how to write your first lines of LightSwitch code! Until next time!&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Go to next article &amp;ndash;&amp;gt; &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/20/beginning-lightswitch-part-5-may-i-defining-user-permissions.aspx"&gt;&lt;em&gt;Part 5: May I? Controlling Access with User Permissions&lt;/em&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10247916" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Queries" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Queries/" /><category term="Beginning LightSwitch Series" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Beginning+LightSwitch+Series/" /></entry><entry><title>Beginning LightSwitch Part 3: Screen Templates, Which One Do I Choose?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/14/beginning-lightswitch-part-3-screen-templates-which-one-do-i-choose.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/12/14/beginning-lightswitch-part-3-screen-templates-which-one-do-i-choose.aspx</id><published>2011-12-14T15:12:00Z</published><updated>2011-12-14T15:12:00Z</updated><content type="html">&lt;p&gt;Welcome to Part 3 of the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/tags/beginning+lightswitch+series/"&gt;Beginning LightSwitch series&lt;/a&gt;! In part 1 and part 2 we learned about &lt;em&gt;entities &lt;/em&gt;and &lt;em&gt;relationships &lt;/em&gt;in LightSwitch and how to use the Data Designer to define them. If you missed them: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx"&gt;Part 1: What’s in a Table? Describing Your Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/08/beginning-lightswitch-part-2-feel-the-love-defining-data-relationships.aspx" target="_blank"&gt;Part 2: Feel the Love. Defining Data Relationships&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In this post I want to talk about &lt;em&gt;screens. &lt;/em&gt;Screens are a common term in everyday life usually denoting a television or computer screen – the shiny thing we look at to interact with the device. In LightSwitch screens present data to the user and form the majority of the application’s user interface (UI). The default LightSwitch application shell presents screens in the center of the application window in a tabbed display. At the top is a ribbon of commands Save and Refresh, and on the left is the navigation menu. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5736.image_5F00_32.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3362.image_5F00_thumb_5F00_15.png" width="676" height="478" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Screens also allow users to search for, edit, insert and delete data in the backend data sources. LightSwitch makes the creation of screens really simple by providing templates you can choose from. You can then use them as is, or customize them further for your needs. Once you have some entities defined (like you learned in the previous posts) then you are ready to create screens. &lt;/p&gt;  &lt;h3&gt;Choosing a Screen Template&lt;/h3&gt;  &lt;p&gt;You can add a screen to your project by clicking the “+ Screens…” button at the top of the Data Designer or by right-clicking on the Screens folder in the Solution Explorer and selecting “Add Screen…”&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8463.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5417.image_5F00_thumb.png" width="272" height="268" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;When you do this the “Add New Screen” dialog appears which asks you to select a screen template as well as the data you want to display on the screen. There are five screen templates in Visual Studio LightSwitch; the &lt;em&gt;Details Screen, Editable Grid Screen, List and Details Screen, New Data Screen, &lt;/em&gt;and &lt;em&gt;Search Data Screen. &lt;/em&gt;Depending on the screen template you choose, your options in the “Screen Data” section on the right changes. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0045.image_5F00_18.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/64053.image_5F00_thumb_5F00_8.png" width="704" height="502" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;When you select the Screen Data drop down, you select the entity you want to use on the screen. On any screen template you choose, the controls are created in a similar way by looking at the entity definition. For instance, the labels for required properties appear as bold text. Also by default, screens use controls that match the underlying data types. So for instance, an editable String property is represented by a TextBox control, a Boolean becomes a CheckBox control, a Phone Number type gets the Phone Number control, etc. This is why it’s important to model your data correctly before creating screens. Although you can customize most of these things on a screen-by-screen basis, LightSwitch reads the settings in your data model to create smart defaults, speeding up the time it takes to create the application. &lt;/p&gt;  &lt;p&gt;Let’s walk through this list of screen templates and some guidelines on why you would choose them. &lt;/p&gt;  &lt;h3&gt;List and Details Screen&lt;/h3&gt;  &lt;p&gt;You use the &lt;em&gt;List and Details Screen&lt;/em&gt; when you want to &lt;strong&gt;see a list of all the records in a table and edit their details on one screen&lt;/strong&gt;. By default, the screen contains two areas. On the left you will see a list that displays the summary of each record. On the right, it displays the details about the record that is selected. You can also choose to add any related entities to the screen and they will display below the detail controls in a grid. Users can use the search &amp;amp; sort functionality on the list to find records and then edit them all on one screen. &lt;/p&gt;  &lt;p&gt;Use this template if you want to allow users to modify all the records in your table on one screen with no additional workflow. This can be particularly well suited for tables that have a smaller number of rows (records), like administration screens, and where only a few users would be modifying the data at the same time. Like all screens that work with multiple data rows, the query will return 45 rows of data at a time by default (you can change this on the screen properties). So it’s usually better to choose entities that don’t have too many or large fields so the application stays responsive as the database grows. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6813.image_5F00_30.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3276.image_5F00_thumb_5F00_14.png" width="714" height="553" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Editable Grid Screen&lt;/h3&gt;  &lt;p&gt;Similar to the List and Details Screen, you can also use the &lt;em&gt;Editable Grid Screen&lt;/em&gt; when you want to modify all the records at the same time on one screen. In this case though, users are presented with a grid of data to edit in a tabular format. Users can press Tab to move from field to field to make changes and edit everything inline. You’ll want to choose this template if your users need to &lt;strong&gt;enter a lot of data quickly into a single table &lt;/strong&gt;like maintenance and lookup tables or where you would only be editing a subset of fields so the user doesn’t need to scroll too much horizontally.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3364.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6318.image_5F00_thumb_5F00_5.png" width="633" height="364" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Details Screen&lt;/h3&gt;  &lt;p&gt;The &lt;em&gt;Details Screen &lt;/em&gt;allows you to &lt;strong&gt;edit a single row of data from a table and optionally, any related data&lt;/strong&gt;. When you click on a link or button to open a single record, the Details screen for that entity is displayed. LightSwitch generates a default details screen for you automatically at runtime if you do not create one yourself. Typically you will want to show all the editable properties for an entity on this screen as well as any related grids of data. This screen template has an additional option in the Add New Screen dialog. Once you select the Screen Data, you will see a checkbox “Use as Default Details Screen” which means to open this screen anytime the user opens a single record from this table anywhere in the system. This is also specified in the Data Designer for the “Default Screen” property for the entity.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4353.image_5F00_26.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8176.image_5F00_thumb_5F00_12.png" width="697" height="495" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;New Data Screen&lt;/h3&gt;  &lt;p&gt;The &lt;em&gt;New Data Screen &lt;/em&gt;allows you to &lt;strong&gt;insert new rows into a table one at a time&lt;/strong&gt;. By default, the screen contains entries for every field of data. Although you can add related entities to this screen as grids, you may want to choose a small subset of just the required or common fields and then flow to another screen to enter the rest. LightSwitch will automatically open the default Details screen after the user saves so this type of “Add New, Save, then Edit” workflow is automatically set up for you. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7802.image_5F00_22.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7080.image_5F00_thumb_5F00_10.png" width="654" height="421" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Search Data Screen&lt;/h3&gt;  &lt;p&gt;You use the &lt;em&gt;Search Data Screen&lt;/em&gt; when you want a user to be able to &lt;strong&gt;locate a single row of data in a table and then open another screen to edit just that row&lt;/strong&gt;. By default, the screen displays a read-only grid of all the rows in a single table (again only 45 are returned at a time by default). To search for a record, you use the search box at the top right of the screen. The search returns all the rows where any string field matches the search term. Clicking on the summary link for the record opens the Details Screen. It is a very common workflow to have users search for records first before allowing edits to them so the search screen provides this behavior automatically. Typically this should be the first screen a user interacts with for large sets of data because it puts them into an efficient workflow that keeps the system responsive even as the database grows. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8562.image_5F00_16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2112.image_5F00_thumb_5F00_7.png" width="727" height="427" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Adding Screens to the Address Book Application &lt;/h3&gt;  &lt;p&gt;Now that you understand what each screen template gives you, let’s create some screens for the Address Book application we’ve been building in this series. At the end of the previous posts we used the List and Details screen so that we could quickly test our data model. If the number of contacts you expect in your address book is relatively small (say less than 100), that screen may be enough to use for the entire application. Users can use the search functionality on the list to find contacts and then edit them all on one screen. &lt;/p&gt;  &lt;p&gt;However, if we wanted to manage thousands of contacts for a business and allow multiple users accessing that data, it’s probably better to put users into a workflow where they first search for a contact and then can either edit one at a time or add a new one if they don’t find the contact they were looking for.&amp;#160; It’s always good to create a simple flowchart of how the application should work:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5342.image_5F00_36.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5430.image_5F00_thumb_5F00_17.png" width="284" height="319" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;First the user searches for a contact and if found then open the Contact Details screen and let them edit all the related contact data. Once the user saves the screen the data is simply redisplayed on the same screen until they close it. If the user does not find the contact they were looking for, they open the New Contact screen which allows them to enter just the contact entity data. When they Save, the Contact Details screen opens and they can finish entering any related data if they need. &lt;/p&gt;  &lt;p&gt;So we just need three screens for our Address Book application; Search Data Screen, New Data Screen, and Details Screen. The order you create your screens is the default order in which they are displayed on the navigation menu. Note that Detail screens will not show up on the navigation menu because a specific record must be selected first. The first screen you create is the first one that is opened by default when the application starts so we’ll want to create the Search Screen first. You can change the screen navigation and how screens appear in the menu by right-clicking on the Solution Explorer and choosing “Edit Screen Navigation”. For a video demonstration on how to edit the screen navigation see: &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh301579"&gt;&lt;em&gt;How Do I: Modify the Navigation of Screens in a LightSwitch Application?&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So first create the Search Contact Screen by right-clicking on the Solution Explorer and selecting “Add Screen..” to open the Add New Screen dialog. Select the Search Data Screen template and then select the Contacts Screen Data and click OK. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0068.image_5F00_38.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3386.image_5F00_thumb_5F00_18.png" width="705" height="505" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next create the New Data Screen in the same manner. This time, select the New Data Screen template. Then select the Contact entity for the Screen Data but do not select any related data. Then click OK&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1134.image_5F00_40.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8562.image_5F00_thumb_5F00_19.png" width="703" height="499" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Finally we will add the Details Screen the same way but this time select all the related entities; EmailAddresses, PhoneNumbers, and Addresses. Also leave the “Use as Default Details Screen” checked. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3201.image_5F00_42.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2318.image_5F00_thumb_5F00_20.png" width="702" height="502" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Run it!&lt;/h3&gt;  &lt;p&gt;Now that we have all our screens defined hit &lt;strong&gt;F5 &lt;/strong&gt;to build and run the application and let’s see what we get. You will notice that the Search screen opens right away and on the navigation menu we have both Search Contacts and Create New Contact screens available. I only have a couple rows of test data in here but if I had hundreds of contacts, LightSwitch would display only 45 rows at a time and we would use the paging control at the bottom of the grid to retrieve the next set of rows. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1157.image_5F00_44.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6428.image_5F00_thumb_5F00_21.png" width="714" height="559" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you click on the last name of a contact it will open the details screen which allows us to edit all the contact information. Notice that LightSwitch also creates links in the first column of the related grids so that you can click on them and open additional detail screens for those records as well. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0574.image_5F00_46.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3617.image_5F00_thumb_5F00_22.png" width="711" height="563" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If the user does not see the contact in the list, they can click on the Create New Contact screen to enter new data. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3288.image_5F00_48.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7827.image_5F00_thumb_5F00_23.png" width="712" height="539" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then once they save this screen, the Contact Details Screen opens for further editing of all the contact information. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7418.image_5F00_50.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7827.image_5F00_thumb_5F00_24.png" width="710" height="538" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If the Search screen is still open, the user can see newly added records by clicking the Refresh button on the ribbon. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4784.image_5F00_52.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2046.image_5F00_thumb_5F00_25.png" width="712" height="541" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Notice we have a LOT of functionality and a totally working Address Book application by just creating a data model and picking some screen templates. &lt;/p&gt;  &lt;h3&gt;Customizing Screen Layouts&lt;/h3&gt;  &lt;p&gt;As I mentioned earlier, all the screen templates are totally customizable so you can use them as-is or modify the layouts completely for your needs. In fact, you as the developer can change the layouts of screens &lt;strong&gt;while the application is running&lt;/strong&gt;. When you are developing your application within Visual Studio LightSwitch you will see a “Design Screen” button at the top right of the running application window. Open a screen and then click that button to open the &lt;em&gt;Screen Customization Mode. &lt;/em&gt;Here you can manipulate the content tree exactly how you like and see your changes in real time. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7024.image_5F00_34.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6355.image_5F00_thumb_5F00_16.png" width="745" height="556" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This comes in extremely handy for quickly modifying the order of fields as well as what, where, and how things are displayed on the screen. However, in order to customize your screen with code or additional data you will need use the Screen Designer back in Visual Studio. For more information on using the Screen Designer to customize screens see: &lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/06/23/tips-and-tricks-for-using-the-screen-designer.aspx" target="_blank"&gt;Tips and Tricks for Using the Screen Designer&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;For more information on building and customizing screens see the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg697761" target="_blank"&gt;&lt;em&gt;Working with Screens&lt;/em&gt;&lt;/a&gt; learn topic on the LightSwitch Developer Center and &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/17/lightswitch-tips-amp-tricks-on-dnrtv.aspx" target="_blank"&gt;LightSwitch Tips &amp;amp; Tricks on dnrTV&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;Wrap Up&lt;/h3&gt;  &lt;p&gt;As you can see the built-in screen templates provide a ton of functionality for you. We now have a fully functional Address Book application and there was no need to write any code to do it! Next post we’ll look at &lt;em&gt;queries &lt;/em&gt;and how to design them in order to filter and sort data on our screens exactly how we want. Until next time!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Go to next article –&amp;gt; &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/15/beginning-lightswitch-part-4-too-much-information-sorting-and-filtering-data-with-queries.aspx"&gt;&lt;em&gt;Part 4: Too much information! Sorting and Filtering Data with Queries&lt;/em&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10247446" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Screens" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Screens/" /><category term="Beginning LightSwitch Series" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Beginning+LightSwitch+Series/" /></entry><entry><title>Beginning LightSwitch Part 2: Feel the Love - Defining Data Relationships</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/08/beginning-lightswitch-part-2-feel-the-love-defining-data-relationships.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/12/08/beginning-lightswitch-part-2-feel-the-love-defining-data-relationships.aspx</id><published>2011-12-08T15:25:00Z</published><updated>2011-12-08T15:25:00Z</updated><content type="html">&lt;p&gt;Welcome to Part 2 of the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/tags/beginning+lightswitch+series/"&gt;Beginning LightSwitch series&lt;/a&gt;! In the last post we learned about tables, or &lt;em&gt;entities, &lt;/em&gt;in LightSwitch and how to use the Data Designer to define them. If you missed it: &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx"&gt;&lt;em&gt;Beginning LightSwitch Part 1: What’s in a Table? Describing Your Data&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In this article I want to focus on data &lt;em&gt;relationships &lt;/em&gt;as we build upon the data model we started in part 1. &lt;strong&gt;Relationships&lt;/strong&gt; define how information in one table corresponds to information in another table in a database. Or more generically, relationships define how an entity corresponds to another entity in (or across) a data source. You can think of relationships between entities like relationships between things in everyday life. For instance, the relationship between a school and its students is one that exists in the real world. Similarly, a real-world relationship exists between students and the classes that those students attend. In a data model, you may have one entity that contains students and another that contains classes they are attending. When you tie the two entities together, you create a relationship.&lt;/p&gt;  &lt;h3&gt;Building a Better Address Book&lt;/h3&gt;  &lt;p&gt;In the example we started in &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx" target="_blank"&gt;part 1&lt;/a&gt;, we’re building an address book application that manages contacts. In our current data model, we’re only storing one phone number, one email address and one address for our contact. &lt;/p&gt;  &lt;p&gt;&lt;img src="http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3343.image_5F00_10.png" /&gt;&lt;/p&gt;  &lt;p&gt;However, in real life contacts typically have more than one email, phone number, and address information. In order to model this in the database we are building through LightSwitch, we need to define additional tables and relate them to the contact table in a &lt;em&gt;one-to-many &lt;/em&gt;relationship. A &lt;strong&gt;one-to-many relationship &lt;/strong&gt;is probably the most common type of relationship you can define. In our case, this means that &lt;strong&gt;one &lt;/strong&gt;contact can have &lt;strong&gt;many &lt;/strong&gt;email addresses. One contact can have many phone numbers. One contact can also have many physical addresses. &lt;/p&gt;  &lt;p&gt;Let’s start with email address. If we want to collect multiple email addresses for a contact we have a couple options. One option is to add a fixed number of email properties to our contact in the form of Email1, Email2, Email3. This means that we would never be able to collect more than 3 email addresses for any given contact. Depending on the type of application you are building this may be just fine. But if you start adding too many properties with the same meaning (in this case email) to your table, then it’s time to think of a different strategy. Instead we should create an EmailAddress table and define a one-to-many relationship.&lt;/p&gt;  &lt;p&gt;From the Data Designer, click the “New Table” button and define an entity called EmailAddress with two required properties: Email (of type Email Address) and EmailType (of type String).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2543.image_5F00_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7002.image_5F00_thumb_5F00_1.png" width="682" height="452" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For EmailType we’ll create an Choice List, which you learned about in &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx" target="_blank"&gt;Part 1 of the series&lt;/a&gt;. This property will capture the type of email, whether that’s Personal or Work. I’ve also chosen to make the maximum length only 25 characters – we won’t ever need all 255. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1050.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4380.image_5F00_thumb.png" width="671" height="523" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Why don’t we make the maximum length 8 characters, which is the length of the longest value in the choice list? Because if we need to add a value to the choice list later that is a little longer than 8 characters, then we won’t have to change the data model. Disk space is cheap these days so it’s better to err on the side of longer max lengths so that all your data can fit into the underlying table. This avoids having to change the data model too often.&lt;/p&gt;  &lt;h3&gt;Defining Relationships in LightSwitch&lt;/h3&gt;  &lt;p&gt;Now that we have our EmailAddress entity it’s time to define the relationship. Click on the “Relationship…” button at the top of the Data Designer and this will open up the “Add New Relationship” dialog window. In the “To” column select Contact to set up the one-to-many relationship. The multiplicity is set to Many to One by default so we don’t need to change it. Multiplicity defines the type of relationship you want to create. In LightSwitch, you can also specify the multiplicity as One to Zero or One which means that only a maximum of one related entity would be allowed. &lt;/p&gt;  &lt;p&gt;For more information on defining different types of relationships see: &lt;a href="http://msdn.microsoft.com/en-us/library/ff852044.aspx#Multiplicity" target="_blank"&gt;&lt;em&gt;How to: Define Data Relationships&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For information on how to model a many-to-many relationship in LightSwitch see: &lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2010/12/16/how-to-create-a-many-to-many-relationship-andy-kung.aspx"&gt;&lt;em&gt;How to Create a Many-to-Many Relationship&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can also specify what happens to the email addresses when a contact is deleted. By default, this is set to “Restricted”. This means that a user would not be allowed to delete a Contact if they had any Email Addresses. Leaving the setting makes sense if we were working with Customers who had many Orders, for instance, but not in this case. We want LightSwitch to automatically delete any Email Addresses when we delete the Contact, so set the “On Delete Behavior” equal to “Cascade delete”. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4300.image_5F00_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8816.image_5F00_thumb_5F00_2.png" width="630" height="599" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The description at the bottom of the dialog is there to help you understand what you are doing when setting up the relationship. Once you click OK you will see the relationship in the Data Designer which will show all direct relationships to the entity you are working with. Notice that a Contact property is now added to the EmailAddress entity. This is called a &lt;em&gt;navigation property&lt;/em&gt; and represents the Contact to which the EmailAddress belongs.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3782.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8407.image_5F00_thumb_5F00_3.png" width="699" height="503" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Double-click on the Contact entity to open it and you will notice a navigation property to all the EmailAddresses for that Contact. Navigation properties are used by LightSwitch on screens to navigate through your data, so it’s important to model them correctly. &lt;/p&gt;  &lt;p&gt;Now that we’ve got the EmailAddress table defined and a relationship set up, we need to delete the Email property we had previously defined on the Contact itself. Select the Email property and hit the Delete key. Alternatively you can right-click and choose Delete on the menu. Do the same to delete the Address1, Address2, City, State, ZIP and Phone properties as well. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4784.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6428.image_5F00_thumb_5F00_5.png" width="713" height="483" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next, let’s add a PhoneNumber table in the same way we added EmailAddress. You might wonder why we need to create a new table separate from the EmailAddress. This is because an EmailAddress and a PhoneNumber are different aspects of a Contact and have no relation to each other except through the Contact itself. Therefore, we need to create a new table. &lt;/p&gt;  &lt;p&gt;Click the “Add Table” button and define the PhoneNumber entity with two required properties: Phone (of type Phone Number) and PhoneType (of type String). PhoneType will have a Choice List of “Cell”, “Fax”, “Home”, and Work”.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7411.image_5F00_14.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1145.image_5F00_thumb_5F00_6.png" width="705" height="434" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next add the relationship to Contact exactly the same way as before. While the PhoneNumber entity is displayed, click the “Relationship…” button at the top of the Data Designer and specify the relationship to the Contact table. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5751.image_5F00_16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4762.image_5F00_thumb_5F00_7.png" width="605" height="605" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Last but not least, we need to create an Address table to store multiple physical addresses for a Contact. Click the Add Table button and define the Address entity with the following properties AddressType, Address1, Address2, City, State, ZIP. Set the AddressType and Address1 properties as required. We will also specify a Choice List for the the AddressType property with values “Home”, “Work”, and “Other”.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5857.image_5F00_18.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3201.image_5F00_thumb_5F00_8.png" width="715" height="480" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now set up the relationship for Address exactly as before. While the Address entity is displayed, click the “Relationship…” button and specify the relationship to the Contact table. Again we’ll choose “Cascade delete” so that any Addresses are deleted automatically if a Contact is deleted. This makes sense in the case of Contact because if the user deletes the contact from the system all their information should be automatically deleted. Keep in mind, however, that you may not want this behavior in other applications. For instance if you are building an order entry application you would want to restrict deletion of Customers if they had any Orders in the system in order to keep the Order history intact. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0640.image_5F00_20.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4265.image_5F00_thumb_5F00_9.png" width="603" height="661" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now when we open the Contact entity in the Data Designer you can see all the direct relationships.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6320.image_5F00_22.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0640.image_5F00_thumb_5F00_10.png" width="715" height="654" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Testing the Address Book&lt;/h3&gt;  &lt;p&gt;Now that we have the data model designed, let’s quickly test it out by creating a screen. At the top of the Data Designer click the “Screen…” button to open the Add New Screen dialog. We’ll talk more about screens in a future post but for now just select the List and Details screen. Then drop down the Screen Data and select Contacts. Once you do this, you will see checkboxes for the additional related entities we created. Select all of them and click OK. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2112.image_5F00_24.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1220.image_5F00_thumb_5F00_11.png" width="712" height="577" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To build and launch the application hit &lt;strong&gt;F5. &lt;/strong&gt;Now you can enter information using this screen. Click the “+” button on the top of the list box on the left to add new contacts. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1526.image_5F00_26.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2625.image_5F00_thumb_5F00_12.png" width="720" height="557" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Notice that LightSwitch read all the one-to-many relationships we set up in our data model and created a tabbed section of grids below the Contact details for Email Addresses, Phone Numbers and Addresses just like we would expect. The grids are editable by default so you can just type the related data directly into the rows. &lt;/p&gt;  &lt;p&gt;Because we defined the relationships properly in our data model, LightSwitch was able to create a very usable screen for entering our data into all the tables in our database without much work at all. In the next post we’ll dive deeper into the Screen Templates and how to customize the layout of screens. Until next time!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Go to next article –&amp;gt; &lt;/strong&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/14/beginning-lightswitch-part-3-screen-templates-which-one-do-i-choose.aspx"&gt;&lt;em&gt;Part 3: Screen Templates, Which One Do I Choose?&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10244823" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="Data" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Data/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Beginning LightSwitch Series" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Beginning+LightSwitch+Series/" /></entry><entry><title>Beginning LightSwitch Part 1: What’s in a Table? Describing Your Data</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx</id><published>2011-12-06T15:18:00Z</published><updated>2011-12-06T15:18:00Z</updated><content type="html">&lt;p&gt;Welcome to Part 1 of the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/tags/beginning+lightswitch+series/" target="_blank"&gt;Beginning LightSwitch series&lt;/a&gt;! To get things started, we’re going to begin with one of the most important building blocks of a LightSwitch application, the &lt;strong&gt;table&lt;/strong&gt;. Simply put, a table is a way of organizing data in columns and rows. If you’ve ever used Excel or another spreadsheet application you organize your data in rows where each column represents a &lt;strong&gt;field &lt;/strong&gt;of a specific type of data you are collecting. For instance, here’s a table of customer data:&lt;/p&gt;  &lt;p&gt;Customer table.&lt;/p&gt;  &lt;table style="width: 400px" border="1" cellspacing="0" cellpadding="2" width="400"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="135"&gt;&lt;strong&gt;LastName&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="135"&gt;&lt;strong&gt;FirstName&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="128"&gt;&lt;strong&gt;BirthDate&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="135"&gt;Doe&lt;/td&gt;        &lt;td valign="top" width="135"&gt;Jane&lt;/td&gt;        &lt;td valign="top" width="128"&gt;10/20/1972&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="135"&gt;Smith&lt;/td&gt;        &lt;td valign="top" width="154"&gt;John&lt;/td&gt;        &lt;td valign="top" width="163"&gt;11/12/1956&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;When you work with databases, the data is stored in a series of tables this way. You then create relationships between tables to navigate through your data properly. We’ll talk about relationships in the next post. For this post let’s concentrate on how to create and work with tables in LightSwitch.&lt;/p&gt;  &lt;h3&gt;Tables (Entities) in LightSwitch&lt;/h3&gt;  &lt;p&gt;Applications you build with LightSwitch are forms-over-data applications that provide user interfaces for viewing, adding, and modifying data. LightSwitch simplifies the development of these applications by using screens and tables. Because LightSwitch can work with other external data sources that do not necessarily have to come from a database, we sometimes call tables “Data entities” or just “entities” in LightSwitch. So whether you have a table in a database or a list in SharePoint, both the table and the list are &lt;em&gt;entities&lt;/em&gt; in LightSwitch. Similarly, a field in a table or a column in a list is referred to as a “property” of the entity. &lt;/p&gt;  &lt;p&gt;Entities are how LightSwitch represents data and are necessary to assemble an application. You create these data entities by using the built-in application database, or by importing data from an external database, a SharePoint list, or other data source. When you create a new project in LightSwitch, you need to choose whether you want to attach to an existing data source or create a new table. If you choose to create a new table, LightSwitch will create it in the built-in database, also referred to as the &lt;em&gt;intrinsic&lt;/em&gt; database. You then design the table using the Data Designer.&lt;/p&gt;  &lt;p&gt;When you create tables and relate them together you are designing a data model, or &lt;em&gt;schema&lt;/em&gt;. Describing your data this way takes some practice if you’ve never done it before, however, you will see that it’s pretty intuitive using LightSwitch. The better you are at describing your data model, the more LightSwitch can do for you when you create screens later.&lt;/p&gt;  &lt;h3&gt;The LightSwitch Data Designer&lt;/h3&gt;  &lt;p&gt;The Data Designer is where all your data modeling happens in LightSwitch whether you’re attaching to an existing data source or creating a new database. By using the Data Designer, you can define properties on your entities and create relationships between them. LightSwitch handles many typical data management tasks such as field validation, transaction processing, and concurrency conflict resolution for you but you can also customize these tasks by modifying properties in the Properties window, and/or by writing code to override or extend them.&lt;/p&gt;  &lt;p&gt;For a tour of the Data Designer, see &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee256715.aspx" target="_blank"&gt;Data: The Information Behind Your Application&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;For a video demonstration on how to use the Data Designer, see: &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff949858" target="_blank"&gt;How Do I: Define My Data in a LightSwitch Application?&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;  &lt;h3&gt;Creating a “Contact” Entity&lt;/h3&gt;  &lt;p&gt;Let’s walk through a concrete example of creating an entity. Suppose we want to create an application that manages contacts, like an address book. We need to create an entity that stores the contact data. First open &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;Visual Studio LightSwitch&lt;/a&gt; and create a new project called ContactManager.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2772.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1212.image_5F00_thumb.png" width="701" height="677" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;After you click OK on the New Project dialog, the LightSwitch home page will ask you if you want to create a new table or attach to an external data source. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1234.image_5F00_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6683.image_5F00_thumb_5F00_1.png" width="704" height="498" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Click “Create new table” and this will open the Data Designer. Now you can start describing the contact entity. Your cursor will be sitting in the title bar of the entity window when it opens. Name it “Contact” and hit the Enter key. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5432.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3060.image_5F00_thumb_5F00_5.png" width="704" height="497" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Once you do this you will see “Contacts” in the Solution Explorer under the ApplicationData node in the Data Sources folder. &lt;strong&gt;ApplicationData&lt;/strong&gt; represents the intrinsic database that LightSwitch creates for you. &lt;strong&gt;Contacts&lt;/strong&gt; refers to the table in the database that stores all the contact rows (or records). You can also think of this as a collection of entities, that’s why LightSwitch makes it plural for you. &lt;/p&gt;  &lt;p&gt;Now we need to start defining properties on our entity, which correlates to the columns (or fields) on the table. You should notice at this point that the Contact entity has a property called “Id” that you cannot modify. This is an internal field that represents a unique key to the particular row of data. When you model tables in a database, each row in the table has to have a unique key so that a particular row can be located in the table. This Id is called a &lt;em&gt;primary key &lt;/em&gt;as indicated by the picture of the key on the left of the property name. It is always required, unique, and is stored as an integer. LightSwitch handles managing primary keys automatically for you.&lt;/p&gt;  &lt;p&gt;So we now need to think about what properties we want to capture for a contact. We also will need to determine how the data should be stored by specifying the type and whether a value is required or not. I’ve chosen to store the following pieces of data: LastName, FirstName, BirthDate, Gender, Phone, Email, Address1, Address2, City, State and ZIP. Additionally, only the LastName is required so that the user is not forced to enter the other values. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3343.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2783.image_5F00_thumb_5F00_4.png" width="654" height="443" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Also notice that I selected types that most closely match the type of data I want to store. For Phone and Email I selected the “Phone Number” and “Email Address” types. These &lt;em&gt;business types &lt;/em&gt;give you built-in validation and editors on the screens. The data is still stored in the underlying table as strings, but is formatted and validated on the screen automatically for you. Validation of user input is important for keeping your data consistent. From the Properties window you can configure rules like required values, maximum lengths of string properties, number ranges for numeric properties, date ranges for date properties, as well as other settings. You can also write your own custom validation code if you need. &lt;/p&gt;  &lt;p&gt;For more information on validation rules see: &lt;em&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/11/11/common-validation-rules-in-lightswitch-business-applications.aspx" target="_blank"&gt;Common Validation Rules in LightSwitch Business Applications&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;If you don’t see the Properties window hit F4 to open it. Select a property on the entity and you will see the related settings you can configure for it. Depending on the type of data you chose for the property, you will see different settings. All properties have an “Appearance” section in the property window that allow you specify the Display Name that will appear in field labels on screens in the application. By default, if you use &lt;a href="http://en.wikipedia.org/wiki/Pascal_case" target="_blank"&gt;upper camel case (a.k.a Pascal case)&lt;/a&gt; for your entity property names then LightSwitch will put a space between the phrases. For instance, the Display Name for the “LastName” property will become “Last Name” automatically. So it’s best practice to use this casing for your entity properties. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3056.image_5F00_18.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6082.image_5F00_thumb_5F00_8.png" width="272" height="527" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can also enter a “Description” for properties when their names aren’t intuitive enough for the user, or you just want to display a standard help message. The Description is displayed on screens as a &lt;a href="http://en.wikipedia.org/wiki/Tooltip" target="_blank"&gt;Tooltip&lt;/a&gt; when the user hovers their mouse over the data entry control on any screen displaying that field. &lt;/p&gt;  &lt;p&gt;Settings you make here in the Data Designer affect all the screens in the application. Although you can make additional customizations on particular screens if needed, you will spend the bulk of your time configuring your data model here in the Data Designer. That way, you don’t have to configure settings every time you create a new screen. The better you can model your entities, the more LightSwitch can do for you automatically when creating the user interface.&lt;/p&gt;  &lt;p&gt;For the Contact entity let’s set a few additional settings. First, select the Id field and in the Appearance section, uncheck “Display by default”. This makes it so that the property doesn’t show up anywhere in the user interface. As mentioned earlier, the primary key is an internal field used to locate a row in the table and isn’t modifiable so the user does not need to see it on any screens in the application. &lt;/p&gt;  &lt;p&gt;For BirthDate, set the minimum value to 1/1/1900 so that users can’t enter dates before that. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1200.image_5F00_20.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2783.image_5F00_thumb_5F00_9.png" width="270" height="269" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For Gender, we want to display a fixed set of static values to the user: “Female”,“Male”. In order to do this in LightSwitch we can use a &lt;em&gt;Choice List. &lt;/em&gt;Click on “Choice List…” on the Properties window and this will open a window that will let you define the values that are stored in the table and the display name you want the user to see. For our purposes, we just want to store an “F” or “M'” in the underlying database table. Therefore, also set the Maximum Length to 1. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1803.image_5F00_26.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8233.image_5F00_thumb_5F00_12.png" width="684" height="528" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;By default, maximum lengths of strings are set to 255 characters and should handle most cases, but you can change this for your needs. &lt;/p&gt;  &lt;p&gt;Using the Properties window you can also configure settings on the entity itself. Select the title bar of the Contact entity and notice that there is a setting called &lt;strong&gt;Summary Property&lt;/strong&gt;. Summary properties are used to “describe” your entity and are used by LightSwitch to determine what to display when a row of data is represented on a screen. By default, LightSwitch selects the first string property you defined on your entity but you can change that here. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0726.image_5F00_32.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5100.image_5F00_thumb_5F00_15.png" width="271" height="261" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can also create computed properties to use as the summary property when you want to format values or display values from multiple fields. &lt;/p&gt;  &lt;p&gt;For more information on Summary Properties see: &lt;em&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2010/12/07/getting-the-most-out-of-lightswitch-summary-properties.aspx" target="_blank"&gt;Getting the Most out of LightSwitch Summary Properties&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;  &lt;h3&gt;Testing the Contact Entity&lt;/h3&gt;  &lt;p&gt;Now that we have the Contact entity designed, let’s quickly test it out by creating a screen. At the top of the Data Designer click the “Screen…” button to open the Add New Screen dialog. We’ll talk more about screens in a future post but for now just select the List and Details screen. Then drop down the Screen Data and select Contacts and then click OK.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2772.image_5F00_34.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8244.image_5F00_thumb_5F00_16.png" width="699" height="552" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To build and launch the application hit &lt;strong&gt;F5. &lt;/strong&gt;Now you can enter information into the contact table using this screen. Click the “+” button on the top of the list box to add new contacts. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5826.image_5F00_36.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0726.image_5F00_thumb_5F00_17.png" width="707" height="547" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Notice that the labels are displayed properly with spaces and the Last Name is bolded to indicate it’s a required field. Also if you enter invalid data as specified by the settings we made, a validation error will be displayed. When you are done, click the Save button on the ribbon at the top left of the application shell. This will save the data back into your development database. This is just test data stored in your internal database while you develop the application. Real data doesn’t go into the system until you deploy the application to your users.&lt;/p&gt;  &lt;p&gt;In the next post we’ll talk about relationships and build upon our data model. Until next time!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Go to next article –&amp;gt; &lt;/strong&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/08/beginning-lightswitch-part-2-feel-the-love-defining-data-relationships.aspx"&gt;&lt;em&gt;Part 2: Feel the Love - Defining Data Relationships&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10244407" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="Data" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Data/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Beginning LightSwitch Series" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Beginning+LightSwitch+Series/" /></entry><entry><title>Beginning LightSwitch: Getting Started</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/01/beginning-lightswitch-getting-started.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/12/01/beginning-lightswitch-getting-started.aspx</id><published>2011-12-01T15:08:00Z</published><updated>2011-12-01T15:08:00Z</updated><content type="html">&lt;p&gt;For the month of December I&amp;rsquo;m going to write a series of posts aimed at the beginner developer getting up to speed with &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;Visual Studio LightSwitch&lt;/a&gt;. At least I&amp;rsquo;m going to try ;-). It&amp;rsquo;s been a while since I was a beginner myself and started cobbling lines of code together &amp;ndash; in fact, I started when I was 8 years old on an Atari 400. However, folks have told me I have a knack for this writing thing ;-) so I&amp;rsquo;m going to attempt to put myself in a beginner&amp;rsquo;s shoes and try to explain things as clear as I can.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s a ton of information out there on building LightSwitch applications, especially on the &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;LightSwitch Developer Center&lt;/a&gt; but here I want to pull together a cohesive set of entry-level articles that focus on the most important concepts you need to learn in order to build any LightSwitch application. By the way, if you aren&amp;rsquo;t familiar with what LightSwitch is and what it can do I encourage you to &lt;a href="http://www.microsoft.com/visualstudio/en-us/lightswitch/overview" target="_blank"&gt;check out the product overview here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s what I&amp;rsquo;m thinking for the series:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/06/beginning-lightswitch-part-1-what-s-in-a-table-describing-your-data.aspx"&gt;Part 1: What's in a Table? Describing your Data&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/08/beginning-lightswitch-part-2-feel-the-love-defining-data-relationships.aspx" target="_blank"&gt;Part 2: Feel the Love. Defining Data Relationships&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/14/beginning-lightswitch-part-3-screen-templates-which-one-do-i-choose.aspx" target="_blank"&gt;Part 3: Screen Templates - Which One Do I Choose?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/15/beginning-lightswitch-part-4-too-much-information-sorting-and-filtering-data-with-queries.aspx" target="_blank"&gt;Part 4: Too much information! Sorting and Filtering Data with Queries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/20/beginning-lightswitch-part-5-may-i-defining-user-permissions.aspx"&gt;Part 5: May I? Controlling Access with User Permissions&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/12/21/beginning-lightswitch-part-6-i-feel-pretty-customizing-the-quot-look-and-feel-quot-with-themes.aspx"&gt;Part 6: I Feel Pretty! Customizing the "Look and Feel" with Themes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Begining-LightSwitch-508763ea" target="_blank"&gt;Download the Completed Sample App&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Before we get started with the series, the first thing to do is make sure you&amp;rsquo;re all set up with LightSwitch by visiting the &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;LightSwitch Developer Center&lt;/a&gt;. There on the home page you will see clear steps to get started.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=211226"&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/ee402630.Numeral1_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt; &lt;a href="http://go.microsoft.com/fwlink/?LinkID=211226"&gt;Download Visual Studio LightSwitch&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823"&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/ee402630.Numeral2_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt; &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823"&gt;Watch the instructional LightSwitch "How Do I?" videos&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857"&gt;&lt;img border="0" alt="Get essential training" src="http://i.msdn.microsoft.com/ee402630.Numeral3_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857"&gt;Get essential training&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-us/category/vslightswitch"&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/ee402630.Numeral4_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-us/category/vslightswitch"&gt;Ask questions in the LightSwitch forums&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you click on &amp;ldquo;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857"&gt;Get essential training&lt;/a&gt;&amp;rdquo; then you will be taken to the Learn page which is broken down into the sections, Getting Started, Essential Topics and Advanced Topics. If you&amp;rsquo;re a beginner, the getting started section is what you want to start with:&lt;/p&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;Are you completely new to Visual Studio LightSwitch? This information will help you get started using LightSwitch to develop business applications for the desktop or the cloud. Be sure to check out the step-by-step &amp;ldquo;How Do I&amp;rdquo;videos.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff852059.aspx"&gt;&lt;img border="0" alt="Create Your First LightSwitch Application" src="http://i.msdn.microsoft.com/ee402630.Beginner_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt; &lt;a href="http://msdn.microsoft.com/en-us/library/ff852059.aspx"&gt;Create Your First LightSwitch Application&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823"&gt;&lt;img border="0" alt="Watch the LightSwitch How Do I Videos" src="http://i.msdn.microsoft.com/ee402630.Video_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823"&gt; Watch the LightSwitch How Do I Videos&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://go.microsoft.com/?linkid=9741442"&gt;&lt;img border="0" alt="Visual Studio LightSwitch Training Kit" src="http://i.msdn.microsoft.com/ee402630.Training_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt; &lt;a href="http://go.microsoft.com/?linkid=9741442"&gt;Download the Visual Studio LightSwitch Training Kit&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/08/01/getting-started-with-the-lightswitch-starter-kits.aspx"&gt;&lt;img border="0" alt="Visual Studio LightSwitch Starter Kits" src="http://i.msdn.microsoft.com/ee402630.StarterKit_sm(en-us,MSDN.10).png" /&gt;&lt;/a&gt; &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/08/01/getting-started-with-the-lightswitch-starter-kits.aspx"&gt;Get Started with the LightSwitch Starter Kits&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The first link is to a step-by-step walkthrough that shows you how to quickly build a simple contact manager. It should take you 5 to 10 minutes to complete the application so it&amp;rsquo;s a great place to start. Then you can move onto the &amp;ldquo;How Do I&amp;rdquo; videos for more step-by-step video lessons to build a simple order entry application. If you want a super-quick way to get an application started, check out the starter kits. There&amp;rsquo;s currently six available for you to choose from and are full working applications you can use.&lt;/p&gt;
&lt;p&gt;So do your homework kids, and in the next post we&amp;rsquo;ll start to dive into the series starting with my favorite topic &amp;ndash; Data!&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10243097" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Beginning LightSwitch Series" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Beginning+LightSwitch+Series/" /></entry><entry><title>LightSwitch Community &amp; Content Rollup–November 2011</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/11/30/lightswitch-community-amp-content-rollup-november-2011.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/11/30/lightswitch-community-amp-content-rollup-november-2011.aspx</id><published>2011-11-30T15:01:00Z</published><updated>2011-11-30T15:01:00Z</updated><content type="html">&lt;p&gt;A couple months ago I started posting a rollup of interesting community happenings, content, and sites popping up. If you missed those rollups you can check them out here, lot of great content and exciting events happened:    &lt;br /&gt;    &lt;br /&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/09/29/lightswitch-community-amp-content-rollup-september.aspx"&gt;LightSwitch Community &amp;amp; Content Rollup–September 2011&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/31/lightswitch-community-amp-content-rollup-october-2011.aspx"&gt;LightSwitch Community &amp;amp; Content Rollup–October 2011&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here’s a rollup of LightSwitch goodies for November:&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;“LightSwitch Star” Contest&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;&lt;em&gt;&lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx" target="_blank"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 10px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MS VS LightSwitch Star Contest - banners - 300x250" border="0" alt="MS VS LightSwitch Star Contest - banners - 300x250" align="left" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8182.MS-VS-LightSwitch-Star-Contest-_2D00_-banners-_2D00_-300x250_5F00_3.jpg" width="300" height="250" /&gt;&lt;/a&gt;Do you have what it takes to be a LightSwitch Star? Show us your coolest, most productive, LightSwitch business application and &lt;/em&gt;&lt;strong&gt;&lt;i&gt;you could win a Laptop &lt;/i&gt;&lt;/strong&gt;&lt;em&gt;and other great prizes!&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Last month The Code Project launched the &lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;“LightSwitch Star” contest&lt;/a&gt;. You just answer some questions and email them a screenshot or two. They’re looking for apps that show off the most productivity in a business as well as apps that use extensions in a unique, innovative way. Check out the &lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;contest page on The Code Project&lt;/a&gt; for details. &lt;/p&gt;  &lt;p&gt;There were some really cool applications submitted in November! Some were real production apps and some were samples/tutorials. Here’s a breakdown of what was submitted. Vote for your favorites! Prizes are given away each month.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;6 Production Apps&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a name="artTitle"&gt;&lt;/a&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/Church.aspx"&gt;Church+&lt;/a&gt; - Church+ is a comprehensive, extensive and integrated church management application &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/Engineeringapp.aspx" name="artTitle"&gt;Engineering App&lt;/a&gt; - A business application for a structural and architectural engineering company &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/favourite-food.aspx"&gt;Favourite Food App&lt;/a&gt; - The app was created to help remember favourite food &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/timetable_lightswitch.aspx"&gt;LightSwitch Timetable Management Application&lt;/a&gt; - A LightSwitch application used to manage the resources needed to build university timetables &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/PTA-LightSwitch.aspx"&gt;PTA LightSwitch&lt;/a&gt; - A LightSwitch application manages student, parent, and staff information &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/SecurityCentral.aspx"&gt;Security Central&lt;/a&gt; - Security Central is a role based application designed for Corporate Legal and Physical Security Departments &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;7 Tutorials/Samples&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/AcquireImagesLightSwitch.aspx"&gt;Acquiring images from scanners and Webcams in Visual Studio LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/LSUsercontrolIntegration.aspx"&gt;How to integrate Usercontrols in LightSwitch Application&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/LSScheduler.aspx"&gt;LightSwitch: Integrating The ComponentOne Scheduler&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/OnlineOrdering.aspx"&gt;LightSwitch Online Ordering System&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/existingDb_lightswitch.aspx"&gt;Manage existing users and roles using a LightSwitch application&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.youtube.com/watch?v=IFMMYoL5T4s&amp;amp;feature=channel_video_title&amp;amp;noredirect=1"&gt;Migrating Access To LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/LightSwitch/LightSwitchCharts.aspx"&gt;Using Silverlight Pie Charts in Visual Studio LightSwitch&lt;/a&gt;       &lt;br /&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823"&gt;&lt;img style="margin: 0px 0px 7px; display: inline; float: left" border="0" alt="" align="left" src="http://i.msdn.microsoft.com/gg604823.pluralsight-253(en-us,MSDN.10).png" /&gt;&lt;/a&gt;&lt;b&gt;LightSwitch Developer Center: Free Video Training&lt;/b&gt; from Pluralsight &lt;/h3&gt;  &lt;p&gt;We added over an hour and a half of video training to the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823"&gt;Developer Center “How Do I” video page &lt;/a&gt;graciously donated by &lt;a href="http://www.pluralsight-training.net/microsoft/?utm_source=microsoft&amp;amp;utm_medium=sponsored-page&amp;amp;utm_content=lightswitch&amp;amp;utm_campaign=microsoft-sponsored-course"&gt;Pluralsight&lt;/a&gt;!&amp;#160; Check out the modules we added:     &lt;br /&gt;    &lt;br /&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.pluralsight-training.net/microsoft/players/PsodPlayer?author=matt-milner&amp;amp;name=lightswitch-intro&amp;amp;mode=live&amp;amp;clip=0&amp;amp;course=lightswitch-introduction"&gt;1. Introduction to Visual Studio LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.pluralsight-training.net/microsoft/players/PsodPlayer?author=matt-milner&amp;amp;name=lightswitch-data&amp;amp;mode=live&amp;amp;clip=0&amp;amp;course=lightswitch-introduction"&gt;2. Working with Data&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.pluralsight-training.net/microsoft/players/PsodPlayer?author=matt-milner&amp;amp;name=lightswitch-screens&amp;amp;mode=live&amp;amp;clip=0&amp;amp;course=lightswitch-introduction"&gt;3. Working with Screens&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;We also updated &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857"&gt;the essential learning topics&lt;/a&gt; with new content and organized the learning sections better so have a look at all the new training available on the &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;LightSwitch Developer Center&lt;/a&gt;!&amp;#160; &lt;/p&gt;  &lt;h3&gt;Notable Content this Month&lt;/h3&gt;  &lt;p&gt;Here’s some more of the fun things the team and community released in November. &lt;/p&gt;  &lt;h6&gt;Extensions released in November (&lt;a href="http://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=VisualStudioVersion&amp;amp;f%5B0%5D.Value=VSLS&amp;amp;f%5B0%5D.Text=Visual%20Studio%20LightSwitch&amp;amp;sortBy=Popularity"&gt;see all 64 of them here!&lt;/a&gt;):&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://t.co/0W5tQ6qR"&gt;Image Controls for LightSwitch &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/400b1d7a-a6ba-4851-b622-df91e12656e4"&gt;LightSwitchHelpWebsite Cache Table Data Source &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/6beb1508-e025-420b-a01c-677aad550ac6"&gt;Webcam Extension &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Build your own extensions by visiting the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh304488"&gt;LightSwitch Extensibility page&lt;/a&gt; on the &lt;a href="http://msdn.com/lightswitch"&gt;LightSwitch Developer Center&lt;/a&gt;. &lt;/p&gt;  &lt;h6&gt;Team Articles:&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/11/01/msdn-magazine-deploying-lightswitch-applications-to-windows-azure-mike-wade.aspx" target="_blank"&gt;MSDN Magazine November Issue: Deploying LightSwitch Applications to Windows Azure&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/11/11/common-validation-rules-in-lightswitch-business-applications.aspx"&gt;Common Validation Rules in LightSwitch Business Applications&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/11/18/using-the-save-and-query-pipeline-to-archive-deleted-records.aspx"&gt;Using the Save and Query Pipeline to “Archive” Deleted Records&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;Community Content:&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://our.componentone.com/2011/11/21/changing-connection-strings-in-lightswitch/"&gt;Changing Connection Strings in LightSwitch &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/71/Connecting-To-A-CSV-or-Excel-File-Directly-With-LightSwitch.aspx"&gt;Connecting To A .CSV or Excel File Directly With LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://t.co/v6Csr3sf" target="_blank"&gt;Create a screen which Edit and Add Records in a LightSwitch Application&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://t.co/5mgR2ZFz" target="_blank"&gt;How to integrate Usercontrols in LightSwitch Application?&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://bit.ly/uEMp3r" target="_blank"&gt;Native XAML Reporting: Integrating Infragistics Netadvantage Reporting in Visual Studio LightSwitch Applications&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://t.co/5p6W4uKP" target="_blank"&gt;LightSwitch Chat Application Using A Data Source Extension&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://t.co/L3vc4D2u" target="_blank"&gt;Migrating Access to LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://t.co/Xvomhz20" target="_blank"&gt;Using Visual Studio LightSwitch with MySQL&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;Samples (&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh204519"&gt;see all of them here&lt;/a&gt;):&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Common-Validation-Rules-in-397bf46b"&gt;Common Validation Rules in LightSwitch Business Applications&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/How-to-Open-Screen-5a7d5900"&gt;How to Open Screen or Entity Designer from Code in LightSwitch with Macro&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/How-to-open-Browse-with-99bf04c4"&gt;How to Set Default Browser for LightSwitch Web Application with Macro&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;LightSwitch Team Community Sites&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://www.facebook.com/vslightswitch" target="_blank"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px 4px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="" align="left" src="http://badge.facebook.com/badge/151211271561073.1904.953280091.png" width="137" height="84" /&gt;&lt;/a&gt; The &lt;a href="http://www.facebook.com/vslightswitch" target="_blank"&gt;Visual Studio LightSwitch Facebook Page&lt;/a&gt; has been increasing in activity lately. Become a fan! Have fun and interact with us on our wall. Check out the cool stories and resources. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Also here are some other places you can find the LightSwitch team: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/category/vslightswitch"&gt;LightSwitch MSDN Forums&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://msdn.com/lightswitch"&gt;LightSwitch Developer Center&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/lightswitch"&gt;LightSwitch Team Blog&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://twitter.com/#!/VSLightSwitch"&gt;LightSwitch on Twitter&lt;/a&gt; (@VSLightSwitch, #VisualStudio #LightSwitch) &lt;/p&gt;  &lt;h6&gt;Join Us!&lt;/h6&gt;  &lt;p&gt;The community has been using the hash tag #LightSwitch on twitter when posting stuff so it’s easier for me to catch it. &lt;a href="http://twitter.com/#!/search/realtime/%23LightSwitch"&gt;Join the conversation!&lt;/a&gt; And if I missed anything please add a comment to the bottom of this post and let us know!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10242580" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Community" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Community/" /><category term="Videos" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Videos/" /><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Rollup" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Rollup/" /></entry><entry><title>I’m Speaking at Sac.NET User Group Tomorrow, Nov 29th!</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/11/28/i-m-speaking-at-sac-net-user-group-tomorrow.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/11/28/i-m-speaking-at-sac-net-user-group-tomorrow.aspx</id><published>2011-11-28T23:20:07Z</published><updated>2011-11-28T23:20:07Z</updated><content type="html">&lt;p&gt;Tomorrow evening I’ll be presenting &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;Visual Studio LightSwitch&lt;/a&gt; to Sac.NET in the Sacramento area. Please come join us! I always try and make it a fun and lively presentation and I’ll have tons of demos. Here are the details:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;When: &lt;/strong&gt; Tuesday, November 29th at 6:00 PM     &lt;br /&gt;&lt;strong&gt;Where: &lt;/strong&gt;Rancho Cordova Library, 9845 Folsom Blvd, Rancho Cordova, CA 95827    &lt;br /&gt;    &lt;br /&gt;&lt;strong&gt;Building Business Applications in Light Speed using Visual Studio LightSwitch      &lt;br /&gt;&lt;/strong&gt;Visual Studio LightSwitch is the simplest way to build business applications for the desktop and cloud for developers of all skill levels. LightSwitch simplifies the development process by letting you concentrate on the business logic, while LightSwitch handles the common tasks for you. In this demo-heavy session, you will see, end-to-end, how to build and deploy a data-centric business application using LightSwitch. You will also see how professional developers can enhance the LightSwitch experience by tapping into its rich extensibility model.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.sacnetug.org/Event/Index" target="_blank"&gt;See the event details and register here.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Hope to see you there!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10242194" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Speaking" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Speaking/" /><category term="Community" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Community/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /></entry><entry><title>Using the Save and Query Pipeline to “Archive” Deleted Records</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/11/18/using-the-save-and-query-pipeline-to-archive-deleted-records.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/11/18/using-the-save-and-query-pipeline-to-archive-deleted-records.aspx</id><published>2011-11-18T15:35:00Z</published><updated>2011-11-18T15:35:00Z</updated><content type="html">&lt;p&gt;Before Microsoft, I used to work in the health care industry building software for hospitals and health insurance companies. In all of those systems we had detailed audit trails (change logging), authorization systems, and complex business rules to keep patient data safe. One particular requirement that came up often is that we never delete patient information out of the system, it was merely archived or “marked” as deleted. This way we could easily maintain historical data but limit the data sets people worked with to only current patients. &lt;/p&gt;  &lt;p&gt;Fortunately LightSwitch makes this extremely simple because it allows us to tap into the save pipeline to perform data processing before data is saved. We can also tap into the query pipeline to filter data before it’s returned. In this post I’ll show you how you can mark records for deletion without actually deleting them from the database as well as how to filter those records out so the users don’t see them. &lt;/p&gt;  &lt;h4&gt;Tapping into the Save Pipeline&lt;/h4&gt;  &lt;p&gt;The save pipeline runs in the middle tier (a.k.a. logic tier) anytime an entity is being updated, inserted or deleted. This is where you can write business logic that runs as changes are processed on the middle tier and saved to data storage. (For more details on the save pipeline please see &lt;em&gt;&lt;a href="http://www.code-magazine.com/Article.aspx?quickid=1103071" target="_blank"&gt;Getting the Most Out of the Save Pipeline in Visual Studio LightSwitch&lt;/a&gt;.)&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Let’s say we have an application that works with customers. However we don’t ever want to physically delete our customers from the database. There’s a couple ways we can do this. One way is to “move” the record to another table. This is similar to the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/06/22/how-to-create-a-simple-audit-trail-change-log-in-lightswitch.aspx" target="_blank"&gt;audit trail example I showed here&lt;/a&gt;. Another way you can do this is to “mark” the record as deleted by using another field. For instance, let’s take a simple data model of Customer and their Orders. Notice that I’ve created a required field called “IsDeleted” on Customer that is the type Boolean. I’ve unchecked “Display by Default” in the properties window so that the field isn’t visible on any screens. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5314.image_5F00_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1581.image_5F00_thumb_5F00_2.png" width="607" height="553" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In order to mark the IsDeleted field programmatically when a user attempts to delete a customer, just select the Customer entity in the data designer and drop down the “Write Code” button and select &lt;strong&gt;&lt;em&gt;Customers_Deleting&lt;/em&gt;&lt;/strong&gt; method.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8015.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6787.image_5F00_thumb_5F00_3.png" width="560" height="425" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here are the 2 lines of code we need to write:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Customers_Deleting(entity &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Customer&lt;/span&gt;)
&lt;span style="color: green"&gt;    'First discard the changes, in this case this reverts the deletion
    &lt;/span&gt;entity.Details.DiscardChanges()
    &lt;span style="color: green"&gt;'Next, change the IsDeleted flag to &amp;quot;True&amp;quot;
    &lt;/span&gt;entity.IsDeleted = &lt;span style="color: blue"&gt;True
End Sub&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Notice that first we must call DiscardChanges in order to revert the entity back to it’s unchanged state. Then we simply set the IsDeleted field to True. That’s it! Keep in mind when we change the state of an entity like this, the appropriate save pipeline methods will still run. For instance in this case, the Customers_Updating will fire now because we changed the state of the entity from Deleted to Unchanged to Modified. You can check the state of an entity by using the entity.Details.EntityState property. &lt;/p&gt;

&lt;h4&gt;Tapping into the Query Pipeline&lt;/h4&gt;

&lt;p&gt;Now that we’re successfully marking deleted customers, the next thing to do is filter them out of our queries so that they don’t display to the user on any of the screens they work with. In order to apply a global filter or sort on any and all customer entities in the system, there’s a trick you can do. Instead of creating a &lt;a href="http://msdn.microsoft.com/en-us/library/ff852016.aspx" target="_blank"&gt;custom global query&lt;/a&gt; and having to remember to use that query on all your screens, you can simply modify the built-in queries that LightSwitch generates for you. LightSwitch will generate xxx_All, xxx_Single and xxx_SingleOrDefault queries on all entities for you and you can modify them in code. You access them the same way you do the save pipeline methods.&lt;/p&gt;

&lt;p&gt;Drop down the “Write Code” button on the data designer for Customer and scroll down to Query methods and select &lt;strong&gt;&lt;em&gt;Customers_All_PreprocessQuery&lt;/em&gt;&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1588.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5488.image_5F00_thumb_5F00_4.png" width="534" height="420" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This query is the basis of all the queries you create for Customer. I usually use this method to sort records in meaningful ways so that every default query for the entity is sorted on every screen in the system. In this case we need to also filter out any Customers that have the IsDeleted flag set to True, meaning only return records where IsDeleted = False:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Customers_All_PreprocessQuery(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;query &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Linq.&lt;span style="color: #2b91af"&gt;IQueryable&lt;/span&gt;(&lt;span style="color: blue"&gt;Of &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Customer&lt;/span&gt;))
    query = &lt;span style="color: blue"&gt;From &lt;/span&gt;c &lt;span style="color: blue"&gt;In &lt;/span&gt;query
            &lt;strong&gt;&lt;span style="color: blue"&gt;Where &lt;/span&gt;c.IsDeleted = &lt;/strong&gt;&lt;span style="color: blue"&gt;&lt;strong&gt;False&lt;/strong&gt;
            Order By &lt;/span&gt;c.LastName, c.FirstName
&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Notice we also have a related table called Order. I can do a similar filter on the Order entity as well. Depending on how you have users navigate to orders, this may not be necessary. For instance if you only show Orders on Customer detail screens then you don’t have to worry about the extra filter here. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Orders_All_PreprocessQuery(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;query &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Linq.&lt;span style="color: #2b91af"&gt;IQueryable&lt;/span&gt;(&lt;span style="color: blue"&gt;Of &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Order&lt;/span&gt;))
    query = &lt;span style="color: blue"&gt;From &lt;/span&gt;o &lt;span style="color: blue"&gt;In &lt;/span&gt;query
            &lt;strong&gt;&lt;span style="color: blue"&gt;Where &lt;/span&gt;o.Customer.IsDeleted = &lt;/strong&gt;&lt;span style="color: blue"&gt;&lt;strong&gt;False&lt;/strong&gt;
            Order By &lt;/span&gt;o.OrderDate &lt;span style="color: blue"&gt;Descending
End Sub&lt;/span&gt;&lt;/pre&gt;


&lt;h4&gt;See it in Action!&lt;/h4&gt;

&lt;p&gt;Okay time to test this and see if it works. I’ve created a List and Details screen on Customer. When we run this I can perform inserts, updates and deletes like normal. There’s nothing on the screen that needs to be changed and it acts the same as it normally would. &lt;/p&gt;

&lt;p&gt;You mark the records for deletion….&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6371.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7848.image_5F00_thumb_5F00_5.png" width="687" height="409" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;.. and then click save to execute our Customers_Deleting logic. Once I delete a record and save, it disappears from the list on my screen, but it’s still present in the database. We can see that if we look in the actual database Customer table.&amp;#160; &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3323.image_5F00_14.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5282.image_5F00_thumb_5F00_6.png" width="472" height="115" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Leveraging the save and query pipelines can provide you with a lot of power over your data. This is just one of many ways you can use them to manipulate data and write business rules. &lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10238357" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="Data" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Data/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /></entry><entry><title>Common Validation Rules in LightSwitch Business Applications</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/11/11/common-validation-rules-in-lightswitch-business-applications.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/11/11/common-validation-rules-in-lightswitch-business-applications.aspx</id><published>2011-11-11T15:45:00Z</published><updated>2011-11-11T15:45:00Z</updated><content type="html">&lt;p&gt;Checking the validity of data input is a common requirement for any application that interacts with humans (and other systems), particularly business applications. I’ve never seen or written a data-entry application without implementing common validation rules for inputting data. LightSwitch has many ways to implement validation declaratively through the data designer as well as supporting custom code you write. Field (or property) validation is just one aspect of writing business rules in LightSwitch, but it’s definitely an important one. It’s your “first line of defense” in keeping user entered data consistent. &lt;/p&gt;  &lt;p&gt;Although LightSwitch has some built-in business types and declarative validation settings, many times we need to write small snippets of code to check the format of data entered on a screen. Common things in the USA are States, ZIP codes, Social Security Numbers, UPIN, ISBN, etc. But you may also want to prevent things like numeric and symbolic values in people’s or place’s names or a variety of other rules based on string manipulation.&lt;/p&gt;  &lt;p&gt;In this post, I’ll show you how to define declarative rules as well as write custom validation code in LightSwitch. I’ll also show you some common patterns you can use to validate strings. Let’s get started!&lt;/p&gt;  &lt;h3&gt;Declarative Validation Rules &lt;/h3&gt;  &lt;p&gt;First let’s walk through the types of validation you can specify declaratively without having to write any code. Let’s take a customer entity that we’ve designed with the data designer. It has the following fields:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0882.image_5F00_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8080.image_5F00_thumb_5F00_2.png" width="557" height="372" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;Required Fields &amp;amp; Business Types &lt;/h4&gt;  &lt;p&gt;The first step to validating these fields is to determine their types and which ones are required. LightSwitch will automatically handle required fields as well as validation that comes with business types so you can set these up declaratively using the data designer without having to write any code. The built-in business types are Email, Phone, Money and Image but this is an extensibility point so you can &lt;a href="http://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=VisualStudioVersion&amp;amp;f%5B0%5D.Value=VSLS&amp;amp;f%5B0%5D.Text=Visual%20Studio%20LightSwitch&amp;amp;pageIndex=2"&gt;download more&lt;/a&gt;. On our customer entity notice I’m only requiring that LastName is filled out. Required fields prevent the user from saving data if the field is left blank and the labels show up bolded on the screen. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1067.image_5F00_14.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3034.image_5F00_thumb_5F00_6.png" width="497" height="118" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;When any validation fails, a message is displayed when the user’s cursor is in the field or if they click the validation summary at the top of the screen.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7737.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4188.image_5F00_thumb_5F00_5.png" width="593" height="119" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Notice that I have also selected the “Phone Number” and “Email Address” business types for the Phone and Email fields on our customer entity. Business types come with built-in validation and have additional properties that you can set in the properties window to indicate how the validation should work. For Email Address, you can select whether you want to provide a default email domain and if the domain is required:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1057.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2541.image_5F00_thumb_5F00_3.png" width="287" height="580" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For Phone Number you can supply additional formats it should validate against and in what order:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0572.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1452.image_5F00_thumb_5F00_4.png" width="682" height="530" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;Specifying Field Maximum Lengths&lt;/h4&gt;  &lt;p&gt;Another important declarative validation rule is specifying a maximum length. By default all string fields default to 255 characters. This works for most of our fields because they have variable lengths and 255 will be plenty of room for our data. However, the SSN, State, and ZIP fields are fixed lengths of 11, 2 and 10 characters respectively. Anything over that isn’t a valid piece of data. You specify maximum lengths in the properties window at the bottom in the Validation section:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6254.image_5F00_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1057.image_5F00_thumb_5F00_7.png" width="286" height="238" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;Preventing Duplicates with a Unique Index&lt;/h4&gt;  &lt;p&gt;You can also prevent duplicates by including required fields in a unique index. For instance if I wanted to prevent duplicate Last Names in the system then I could include it in the unique index. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3108.image_5F00_18.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6354.image_5F00_thumb_5F00_8.png" width="290" height="292" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note that this adds the field to a unique index for the table and is enforced by the database. So the validation message will appear after the data is saved and checked on the server side. In the case of my customer entity this is not a good idea to limit duplicates this way because it’s pretty common to have customers with the same last name. You might consider using SSN but then we’d have to make this a required field and only customers with an SSN would be allowed into the system. This is too restrictive in this case, but including fields in a unique index can work well for other types of data entities where you want to prevent duplicate records. &lt;/p&gt;  &lt;h3&gt;Custom Validation Rules&lt;/h3&gt;  &lt;p&gt;When you can’t express a validation rule declaratively then you need to write some code. To write custom validation code, select the property you want on the entity then drop down the “Write Code” button and select the &lt;em&gt;property_&lt;/em&gt;Validate method:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1376.image_5F00_20.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0804.image_5F00_thumb_5F00_9.png" width="481" height="152" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This will open the code editor to a method stub that allows you to write the custom validation code. When a rule fails, you use the results object to add your error message. &lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;LastName_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
    &lt;span style="color: green"&gt;' Check the rule, if it fails then display an error message on the field:
    &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;&amp;lt;Error Message&amp;gt;&amp;quot;&lt;/span&gt;)
&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;You can also specify warnings and informational messages as well. Only error messages prevent data from being saved. To specify a warning or informational message on a field use the &lt;strong&gt;AddPropertyResult &lt;/strong&gt;method and pass it the level of severity:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2045.image_5F00_22.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1462.image_5F00_thumb_5F00_10.png" width="758" height="162" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also specify entity-level errors which aren’t specific to certain fields, instead they will only show up in the validation summary at the top of the screen. You use the &lt;strong&gt;AddEntityError &lt;/strong&gt;and &lt;strong&gt;AddEntityResult &lt;/strong&gt;methods for this. These property validation methods run on the client first and then again on the server, however you just write them once and LightSwitch will take care of calling them at the appropriate times. For a deeper understanding of the validation framework please read: &lt;em&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2010/08/30/overview-of-data-validation-in-lightswitch-applications-prem-ramanathan.aspx" target="_blank"&gt;Overview of Data Validation in LightSwitch Applications&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;Simple String Validation &amp;amp; Formatting&lt;/h4&gt;

&lt;p&gt;The first rule I want to enforce is that the State field should always be entered in uppercase. There are a lot of string methods you can use to manipulate and validate string data. For instance to format strings in a variety of ways you can use the &lt;a href="http://msdn.microsoft.com/en-us/library/fht0f5be(VS.95).aspx" target="_blank"&gt;String.Format() method&lt;/a&gt;. There are also methods to find characters at certain positions (&lt;a href="http://msdn.microsoft.com/en-us/library/system.string.indexof(VS.95).aspx" target="_blank"&gt;IndexOf&lt;/a&gt;), to check if a string contains another string (&lt;a href="http://msdn.microsoft.com/en-us/library/dy85x1sa(VS.95).aspx" target="_blank"&gt;Contains&lt;/a&gt;), to return parts of strings (&lt;a href="http://msdn.microsoft.com/en-us/library/system.string.substring(VS.95).aspx" target="_blank"&gt;Substring&lt;/a&gt;), to trim whitespace (&lt;a href="http://msdn.microsoft.com/en-us/library/system.string.trim(VS.95).aspx" target="_blank"&gt;Trim&lt;/a&gt;), and much much more. &lt;a href="http://msdn.microsoft.com/en-us/library/fht0f5be(VS.95).aspx" target="_blank"&gt;See the documentation for all the string methods available to you.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to format the State field we can simply use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.string.toupper(VS.95).aspx" target="_blank"&gt;ToUpper() method&lt;/a&gt;. Since State isn’t a required field, we first check to see if the State property has a value and if so we make it upper case. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;State_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
&lt;span style="color: blue"&gt;    If Me&lt;/span&gt;.State &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
        Me&lt;/span&gt;.State = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.State.ToUpper
    &lt;span style="color: blue"&gt;End If
End Sub&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Notice that this doesn’t report a validation error to the user, it just formats the string they enter. You can also use the &lt;em&gt;property_&lt;/em&gt;Validate methods to perform formatting as well because the _Validate method will fire when the user tabs out of the field when the method runs on the client. However we still need to validate whether they entered a valid State code – “AA” is currently allowed and this isn’t a valid U.S. State. In order to validate all the possible state code combinations we can use Regular Expressions. &lt;/p&gt;

&lt;h4&gt;Using Regular Expressions&lt;/h4&gt;

&lt;p&gt;Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. Regular expressions are used all over the web to validate user input. In fact, one of my favorite sites is &lt;a href="http://www.RegExLib.com"&gt;www.RegExLib.com&lt;/a&gt; which has thousands of community submitted patterns you can use in your own validation rules. In order to use regular expressions in your _Validate methods you use the RegEx class located in the System.Text.RegularExpressions namespave. So in order to check that the State is a valid US State we can write the following &lt;strong&gt;in bold&lt;/strong&gt;:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;strong&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Text.RegularExpressions&lt;/strong&gt;

&lt;span style="color: blue"&gt;Namespace &lt;/span&gt;LightSwitchApplication
    &lt;span style="color: blue"&gt;Public Class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Customer

        &lt;/span&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;State_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
            &lt;span style="color: blue"&gt;If Me&lt;/span&gt;.State &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
                Me&lt;/span&gt;.State = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.State.ToUpper

&lt;strong&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;                Dim &lt;/span&gt;pattern = &lt;span style="color: #a31515"&gt;&amp;quot;^(?:(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|&amp;quot; &lt;/span&gt;+
                              &lt;span style="color: #a31515"&gt;&amp;quot;LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|&amp;quot; &lt;/span&gt;+
                              &lt;span style="color: #a31515"&gt;&amp;quot;T[NX]|UT|V[AIT]|W[AIVY]))$&amp;quot;
&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;                &lt;br /&gt;                If Not &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.State, pattern) &lt;span style="color: blue"&gt;Then
                    &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;Please enter a valid US State.&amp;quot;&lt;/span&gt;)
                &lt;span style="color: blue"&gt;End If
&lt;/span&gt;&lt;/strong&gt;&lt;span style="color: blue"&gt;            End If
        End Sub
    End Class
End Namespace&lt;/span&gt;&lt;/pre&gt;&lt;/pre&gt;

&lt;p&gt;Similarly we can use regular expressions to check ZIP codes as well. However I want to allow both 5 digit and 9 digit ZIP codes. I also want to allow the user to not have to specify the dash so we’ll do a little formatting as well first.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;ZIP_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
&lt;span style="color: blue"&gt;    If Me&lt;/span&gt;.ZIP &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
        &lt;/span&gt;&lt;span style="color: green"&gt;'Add the dash if the user didn't enter it and the ZIP code is 9 characters
        &lt;/span&gt;&lt;span style="color: blue"&gt;If Not Me&lt;/span&gt;.ZIP.Contains(&lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;) &lt;span style="color: blue"&gt;AndAlso Me&lt;/span&gt;.ZIP.Length = 9 &lt;span style="color: blue"&gt;Then
            Me&lt;/span&gt;.ZIP = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.ZIP.Substring(0, 5) + &lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot; &lt;/span&gt;+ &lt;span style="color: blue"&gt;Me&lt;/span&gt;.ZIP.Substring(5)
        &lt;span style="color: blue"&gt;End If
        &lt;/span&gt;&lt;span style="color: green"&gt;'Now validate based on regular expression pattern
        &lt;/span&gt;&lt;span style="color: blue"&gt;If Not &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.ZIP, &lt;span style="color: #a31515"&gt;&amp;quot;^\d{5}$|^\d{5}-\d{4}$&amp;quot;&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
             &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;Please enter a valid US ZIP code.&amp;quot;&lt;/span&gt;)
&lt;span style="color: blue"&gt;        End If
    End If
End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Another rule I want to enforce is the SSN format that has the pattern “3 digits (dash) 2 digits (dash) 4 digits”. I want to do the same type of thing we did above where we won’t require the user to enter the dashes. So we can write the following:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;SSN_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
&lt;span style="color: blue"&gt;    If Me&lt;/span&gt;.SSN &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
        &lt;/span&gt;&lt;span style="color: green"&gt;'Add the dashes if the user didn't enter it and the SSN is 9 characters
        &lt;/span&gt;&lt;span style="color: blue"&gt;If Not Me&lt;/span&gt;.SSN.Contains(&lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;) &lt;span style="color: blue"&gt;AndAlso Me&lt;/span&gt;.SSN.Length = 9 &lt;span style="color: blue"&gt;Then
            Me&lt;/span&gt;.SSN = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.SSN.Substring(0, 3) + &lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot; &lt;/span&gt;+ &lt;span style="color: blue"&gt;Me&lt;/span&gt;.SSN.Substring(3, 2) + &lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot; &lt;/span&gt;+ &lt;span style="color: blue"&gt;Me&lt;/span&gt;.SSN.Substring(5)
        &lt;span style="color: blue"&gt;End If

        &lt;/span&gt;&lt;span style="color: green"&gt;'Now validate based on regular expression pattern
        &lt;/span&gt;&lt;span style="color: blue"&gt;If Not &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.SSN, &lt;span style="color: #a31515"&gt;&amp;quot;^\d{3}-\d{2}-\d{4}$&amp;quot;&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
            &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;Please enter a valid SSN (i.e. 123-45-6789).&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;End If
    End If
End Sub&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;You can do a lot with regular expressions and string manipulation. The last rule I want to enforce is not allowing users to enter numbers or symbols in the LastName and FirstName fields. They should only contain alphabetical characters and spaces are allowed. We can do something like this to enforce that:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;LastName_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
&lt;span style="color: blue"&gt;    If Me&lt;/span&gt;.LastName &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
        &lt;/span&gt;&lt;span style="color: green"&gt;'This pattern only allows letters and spaces
        &lt;/span&gt;&lt;span style="color: blue"&gt;If Not &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.LastName, &lt;span style="color: #a31515"&gt;&amp;quot;^[a-zA-Z\s]+$&amp;quot;&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
            &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;Last Name can only contain alphabetical characters.&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;End If
    End If
End Sub

Private Sub &lt;/span&gt;FirstName_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
&lt;span style="color: blue"&gt;    If Me&lt;/span&gt;.FirstName &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
        &lt;/span&gt;&lt;span style="color: green"&gt;'This pattern only allows letters and spaces
        &lt;/span&gt;&lt;span style="color: blue"&gt;If Not &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.LastName, &lt;span style="color: #a31515"&gt;&amp;quot;^[a-zA-Z\s]+$&amp;quot;&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
            &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;First Name can only contain alphabetical characters.&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;End If
    End If
End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Notice that in this last example I’m using the same pattern. You’ll most likely have fields across entities in your application where you’ll want to use the same validation checks. When you start copying and duplicating code you should stop and think about consolidating it into a single library or class that you can call. This way if you have a bug in your validation code you fix it in just one place. Remember, the less code you write the less bugs you’ll have. ;-)&lt;/p&gt;

&lt;h4&gt;Creating a Common Validation Module&lt;/h4&gt;

&lt;p&gt;Let’s create a validation module that we can call from our validation methods that encapsulates all the types of validation routines we’d want to support across all the entities in our application. In the Solution Explorer flip to “File View” and under the Common project expand the UserCode folder. Right-click and add a new Module. I’ll name it CommonValidation.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6735.image_5F00_26.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4101.image_5F00_thumb_5F00_12.png" width="578" height="431" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make these validation rules easy to discover and call from our _Validate methods we’ll create them as &lt;a href="http://msdn.microsoft.com/en-us/library/bb384936.aspx" target="_blank"&gt;Extension Methods&lt;/a&gt;. Basically extensions methods “extend” types, like a string or integer or any other object type with your own custom methods. What’s cool is they appear in IntelliSense with you type the dot “.” after the type. To place extension methods in our module we just need to import the&amp;#160; System.Runtime.CompilerServices and then attribute our method with the &amp;lt;Extension()&amp;gt; attribute. &lt;/p&gt;

&lt;p&gt;Let’s take a simple example before we move our complex validation code in here. For instance let’s create an extension method that extends a string type with a method called “MyMethod”. The first parameter to your extension method is the type you are extending. Here’s how we could write the module. (Notice I added the comment section by typing three single quotes (‘’’) above the &amp;lt;Extension&amp;gt;):&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Runtime.CompilerServices

&lt;span style="color: blue"&gt;Module &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CommonValidation
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' This is my extension method that does nothing at the moment. ;-)
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;value&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;extend the string type&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Extension&lt;/span&gt;()&amp;gt;
    &lt;span style="color: blue"&gt;Public Sub &lt;/span&gt;MyMethod(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As String&lt;/span&gt;)
        &lt;span style="color: green"&gt;'Do something
    &lt;/span&gt;&lt;span style="color: blue"&gt;End Sub
End Module
&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;If we flip back to one of the &lt;em&gt;property_&lt;/em&gt;Validate methods then we will now see this extension method in IntelliSense on any string type. (You need to flip to the “All” tab).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2860.image_5F00_28.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0486.image_5F00_thumb_5F00_13.png" width="640" height="230" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice there are a lot of “built-in” extension methods in the .NET framework once you flip to the “All” tab in IntelliSense. So if you were wondering why the icons looked different now you know why :-). Extension methods are a great way to add additional functionality to a type without having to change the implementation of the actual class. &lt;/p&gt;

&lt;p&gt;Now sometimes we’ll need to pass parameters and/or return a value from our extension method. Any parameters you specify after the first one in an extension method becomes a parameter the caller needs to pass. You can also return values from extension methods by declaring them as a Function instead. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Runtime.CompilerServices

&lt;span style="color: blue"&gt;Module &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CommonValidation
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' This is my extension method that still does nothing. :-)
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;value&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;extend the string type&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;param&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;demoing parameter&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Extension&lt;/span&gt;()&amp;gt;
    &lt;span style="color: blue"&gt;Public Function &lt;/span&gt;MyMethod(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As String&lt;/span&gt;, param &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;) &lt;span style="color: blue"&gt;As Boolean
        &lt;/span&gt;&lt;span style="color: green"&gt;'Do something
        &lt;/span&gt;&lt;span style="color: blue"&gt;Return True
    End Function
End Module
&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;If we use this extension method now, you’ll see that a boolean parameter is required. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2538.image_5F00_30.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0407.image_5F00_thumb_5F00_14.png" width="489" height="160" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let’s start moving our validation methods in here. Let’s start with the State validation method. Notice in this method that we first format the value by making it upper case. In order to change the value of the type we’re extending we just pass the parameter ByRef instead of ByVal. I also want to allow passing of a parameter that indicates whether the field can be empty. So now here is our CommonValidation module with an IsState extension method:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Runtime.CompilerServices
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Text.RegularExpressions

&lt;span style="color: blue"&gt;Module &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CommonValidation
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Checks if the string is formatted as a 2 character US state code
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;state&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;string type extension&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;isEmptyOK&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if empty values are allowed, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if the string is a valid US state, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Extension&lt;/span&gt;()&amp;gt;
    &lt;span style="color: blue"&gt;Public Function &lt;/span&gt;IsState(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;state &lt;span style="color: blue"&gt;As String&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;isEmptyOK &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;) &lt;span style="color: blue"&gt;As Boolean
        If &lt;/span&gt;state &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
            &lt;/span&gt;&lt;span style="color: green"&gt;'States should always be upper case
            &lt;/span&gt;state = state.ToUpper

            &lt;span style="color: green"&gt;'Now validate based on regular expression pattern
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;pattern = &lt;span style="color: #a31515"&gt;&amp;quot;^(?:(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|&amp;quot; &lt;/span&gt;+
                          &lt;span style="color: #a31515"&gt;&amp;quot;LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|&amp;quot; &lt;/span&gt;+
                          &lt;span style="color: #a31515"&gt;&amp;quot;T[NX]|UT|V[AIT]|W[AIVY]))$&amp;quot;

            &lt;/span&gt;&lt;span style="color: blue"&gt;Return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(state, pattern)
        &lt;span style="color: blue"&gt;Else
            Return &lt;/span&gt;isEmptyOK
        &lt;span style="color: blue"&gt;End If
    End Function
End Module
&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Notice the nice IntelliSense we now get back in the _Validate methods when we call our extension method:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2548.image_5F00_32.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5661.image_5F00_thumb_5F00_15.png" width="490" height="161" /&gt;&lt;/a&gt;&lt;/p&gt;







&lt;p&gt;To finish off the State_Validate method all we need to do is check the return value to determine if we should add the property error or not:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;State_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
&lt;span style="color: blue"&gt;    If Not Me&lt;/span&gt;.State.IsState(&lt;span style="color: blue"&gt;True&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
        &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;Please enter a valid US State.&amp;quot;&lt;/span&gt;)
    &lt;span style="color: blue"&gt;End If
End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;OK cool! So here are all of the extension validation methods in the module:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Runtime.CompilerServices
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Text.RegularExpressions

&lt;span style="color: blue"&gt;Module &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CommonValidation
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Checks if the string is formatted as a 2 character US state code
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;state&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;string type extension&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;isEmptyOK&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if empty values are allowed, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if the string is a valid US state, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Extension&lt;/span&gt;()&amp;gt;
    &lt;span style="color: blue"&gt;Public Function &lt;/span&gt;IsState(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;state &lt;span style="color: blue"&gt;As String&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;isEmptyOK &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;) &lt;span style="color: blue"&gt;As Boolean
        If &lt;/span&gt;state &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
            &lt;/span&gt;&lt;span style="color: green"&gt;'States should always be upper case
            &lt;/span&gt;state = state.ToUpper

            &lt;span style="color: green"&gt;'Now validate based on regular expression pattern
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;pattern = &lt;span style="color: #a31515"&gt;&amp;quot;^(?:(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|&amp;quot; &lt;/span&gt;+
                          &lt;span style="color: #a31515"&gt;&amp;quot;LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|&amp;quot; &lt;/span&gt;+
                          &lt;span style="color: #a31515"&gt;&amp;quot;T[NX]|UT|V[AIT]|W[AIVY]))$&amp;quot;

            &lt;/span&gt;&lt;span style="color: blue"&gt;Return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(state, pattern)
        &lt;span style="color: blue"&gt;Else
            Return &lt;/span&gt;isEmptyOK
        &lt;span style="color: blue"&gt;End If
    End Function
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Checks if the string is formatted as a valid US ZIP code
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;zip&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;string type extension&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;isEmptyOK&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if empty values are allowed, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if the string is a valid ZIP code, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Extension&lt;/span&gt;()&amp;gt;
    &lt;span style="color: blue"&gt;Public Function &lt;/span&gt;IsZIP(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;zip &lt;span style="color: blue"&gt;As String&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;isEmptyOK &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;) &lt;span style="color: blue"&gt;As Boolean
        If &lt;/span&gt;zip &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
            &lt;/span&gt;&lt;span style="color: green"&gt;'Add the dash if the user didn't enter it and the ZIP code is 9 characters
            &lt;/span&gt;&lt;span style="color: blue"&gt;If Not &lt;/span&gt;zip.Contains(&lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;) &lt;span style="color: blue"&gt;AndAlso &lt;/span&gt;zip.Length = 9 &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;zip = zip.Substring(0, 5) + &lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot; &lt;/span&gt;+ zip.Substring(5)
            &lt;span style="color: blue"&gt;End If
            &lt;/span&gt;&lt;span style="color: green"&gt;'Now validate based on regular expression pattern
            &lt;/span&gt;&lt;span style="color: blue"&gt;Return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(zip, &lt;span style="color: #a31515"&gt;&amp;quot;^\d{5}$|^\d{5}-\d{4}$&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;Else
            Return &lt;/span&gt;isEmptyOK
        &lt;span style="color: blue"&gt;End If
    End Function
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Checks if the string is formatted as a Social Security Number
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;ssn&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;string type extension&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;isEmptyOK&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if empty values are allowed, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if the string is a valid SSN, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Extension&lt;/span&gt;()&amp;gt;
    &lt;span style="color: blue"&gt;Public Function &lt;/span&gt;IsSSN(&lt;span style="color: blue"&gt;ByRef &lt;/span&gt;ssn &lt;span style="color: blue"&gt;As String&lt;/span&gt;, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;isEmptyOK &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;) &lt;span style="color: blue"&gt;As Boolean
        If &lt;/span&gt;ssn &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
            &lt;/span&gt;&lt;span style="color: green"&gt;'Add the dashes if the user didn't enter it and the SSN is 9 characters
            &lt;/span&gt;&lt;span style="color: blue"&gt;If Not &lt;/span&gt;ssn.Contains(&lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot;&lt;/span&gt;) &lt;span style="color: blue"&gt;AndAlso &lt;/span&gt;ssn.Length = 9 &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;ssn = ssn.Substring(0, 3) + &lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot; &lt;/span&gt;+ ssn.Substring(3, 2) + &lt;span style="color: #a31515"&gt;&amp;quot;-&amp;quot; &lt;/span&gt;+ ssn.Substring(5)
            &lt;span style="color: blue"&gt;End If

            &lt;/span&gt;&lt;span style="color: green"&gt;'Now validate based on regular expression pattern
            &lt;/span&gt;&lt;span style="color: blue"&gt;Return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(ssn, &lt;span style="color: #a31515"&gt;&amp;quot;^\d{3}-\d{2}-\d{4}$&amp;quot;&lt;/span&gt;)
        &lt;span style="color: blue"&gt;Else
            Return &lt;/span&gt;isEmptyOK
        &lt;span style="color: blue"&gt;End If
    End Function

    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Checks if the string contains only upper and lower case letters
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;value&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;string type extension&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;isEmptyOK&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if empty values are allowed, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;isWhitespaceOK&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if spaces are allowed, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Extension&lt;/span&gt;()&amp;gt;
    &lt;span style="color: blue"&gt;Public Function &lt;/span&gt;IsAlpha(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As String&lt;/span&gt;,
                            &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;isEmptyOK &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;,
                            &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;isWhitespaceOK &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;) &lt;span style="color: blue"&gt;As Boolean
        If &lt;/span&gt;value &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
            &lt;/span&gt;&lt;span style="color: green"&gt;'Validation for strings that must be Alphabetical characters only. 
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;pattern &lt;span style="color: blue"&gt;As String
            If &lt;/span&gt;isWhitespaceOK &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;&lt;span style="color: green"&gt;'Allows spaces 
                &lt;/span&gt;pattern = &lt;span style="color: #a31515"&gt;&amp;quot;^[a-zA-Z\s]+$&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;Else
                &lt;/span&gt;&lt;span style="color: green"&gt;'No spaces
                &lt;/span&gt;pattern = &lt;span style="color: #a31515"&gt;&amp;quot;^[a-zA-Z]+$&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;End If

            Return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(value, pattern)
        &lt;span style="color: blue"&gt;Else
            Return &lt;/span&gt;isEmptyOK
        &lt;span style="color: blue"&gt;End If
    End Function

    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' Checks if the string contains only upper and lower case letters and/or numbers
    ''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/summary&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;value&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;string type extension&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;isEmptyOK&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if empty values are allowed, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;param name=&amp;quot;isWhitespaceOK&amp;quot;&amp;gt;&lt;/span&gt;&lt;span style="color: green"&gt;True if spaces are allowed, otherwise false&lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;/param&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
    &lt;/span&gt;&lt;span style="color: green"&gt;''' &lt;/span&gt;&lt;span style="color: gray"&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;
    &lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Extension&lt;/span&gt;()&amp;gt;
    &lt;span style="color: blue"&gt;Public Function &lt;/span&gt;IsAlphaNumeric(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;value &lt;span style="color: blue"&gt;As String&lt;/span&gt;,
                                   &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;isEmptyOK &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;,
                                   &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;isWhitespaceOK &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;) &lt;span style="color: blue"&gt;As Boolean
        If &lt;/span&gt;value &amp;lt;&amp;gt; &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
            &lt;/span&gt;&lt;span style="color: green"&gt;'Validation for strings that must be AlphaNumeric characters only. 
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;pattern &lt;span style="color: blue"&gt;As String
            If &lt;/span&gt;isWhitespaceOK &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;&lt;span style="color: green"&gt;'Allows spaces 
                &lt;/span&gt;pattern = &lt;span style="color: #a31515"&gt;&amp;quot;^[a-zA-Z0-9\s]+$&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;Else
                &lt;/span&gt;&lt;span style="color: green"&gt;'No spaces
                &lt;/span&gt;pattern = &lt;span style="color: #a31515"&gt;&amp;quot;^[a-zA-Z0-9]+$&amp;quot;
            &lt;/span&gt;&lt;span style="color: blue"&gt;End If

            Return &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Regex&lt;/span&gt;.IsMatch(value, pattern)
        &lt;span style="color: blue"&gt;Else
            Return &lt;/span&gt;isEmptyOK
        &lt;span style="color: blue"&gt;End If
    End Function
End Module
&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;And finally, our customer entity that calls these methods. Notice how much cleaner the code is now and we can reuse these across any entity in the application.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Namespace &lt;/span&gt;LightSwitchApplication
    &lt;span style="color: blue"&gt;Public Class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Customer

        &lt;/span&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;State_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
            &lt;span style="color: blue"&gt;If Not Me&lt;/span&gt;.State.IsState(&lt;span style="color: blue"&gt;True&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;Please enter a valid US State.&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;End If
        End Sub

        Private Sub &lt;/span&gt;SSN_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
            &lt;span style="color: blue"&gt;If Not Me&lt;/span&gt;.SSN.IsSSN(&lt;span style="color: blue"&gt;True&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;Please enter a valid SSN (i.e. 123-45-6789).&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;End If
        End Sub

        Private Sub &lt;/span&gt;ZIP_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
            &lt;span style="color: blue"&gt;If Not Me&lt;/span&gt;.ZIP.IsZIP(&lt;span style="color: blue"&gt;True&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;Please enter a valid US ZIP code.&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;End If
        End Sub

        Private Sub &lt;/span&gt;LastName_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
            &lt;span style="color: blue"&gt;If Not Me&lt;/span&gt;.LastName.IsAlpha(&lt;span style="color: blue"&gt;False&lt;/span&gt;, &lt;span style="color: blue"&gt;True&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;Last Name can only contain alphabetical characters.&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;End If
        End Sub

        Private Sub &lt;/span&gt;FirstName_Validate(results &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EntityValidationResultsBuilder&lt;/span&gt;)
            &lt;span style="color: blue"&gt;If Not Me&lt;/span&gt;.FirstName.IsAlpha(&lt;span style="color: blue"&gt;True&lt;/span&gt;, &lt;span style="color: blue"&gt;True&lt;/span&gt;) &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;results.AddPropertyError(&lt;span style="color: #a31515"&gt;&amp;quot;First Name can only contain alphabetical characters.&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;End If
        End Sub
    End Class
End Namespace
&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;To pull this all together into a concrete example I’ve included the sample code here:
  &lt;br /&gt;&lt;a title="http://code.msdn.microsoft.com/Common-Validation-Rules-in-397bf46b" href="http://code.msdn.microsoft.com/Common-Validation-Rules-in-397bf46b"&gt;http://code.msdn.microsoft.com/Common-Validation-Rules-in-397bf46b&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this helps get you started writing your own more complex business rules and validation methods for your LightSwitch applications.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10236048" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="Data" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Data/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /></entry><entry><title>LightSwitch Community &amp; Content Rollup–October 2011</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/31/lightswitch-community-amp-content-rollup-october-2011.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/10/31/lightswitch-community-amp-content-rollup-october-2011.aspx</id><published>2011-10-31T19:59:54Z</published><updated>2011-10-31T19:59:54Z</updated><content type="html">&lt;p&gt;Last month I started posting a rollup of interesting community happenings, content, and sites popping up. Particularly last month we had an explosion of extensions and a great list of community sites to check out:&lt;/p&gt;  &lt;h3&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/09/29/lightswitch-community-amp-content-rollup-september.aspx"&gt;LightSwitch Community &amp;amp; Content Rollup–September&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;Here’s a rollup of October tricks and treats! &lt;/p&gt;  &lt;h4&gt;&lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;“LightSwitch Star” Contest&lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MS VS LightSwitch Star Contest - banners - 728x90" border="0" alt="MS VS LightSwitch Star Contest - banners - 728x90" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8512.MS-VS-LightSwitch-Star-Contest-_2D00_-banners-_2D00_-728x90_5F00_3.jpg" width="728" height="90" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Do you have what it takes to be a LightSwitch Star? Show us your coolest, most productive, LightSwitch business application and &lt;/em&gt;&lt;strong&gt;&lt;i&gt;you could win a Laptop &lt;/i&gt;&lt;/strong&gt;&lt;em&gt;and other great prizes!&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Today The Code Project launched the &lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;“LightSwitch Star” contest&lt;/a&gt;! Just answer the questions on the submission template and either create a YouTube video or write an article for Code Project explaining your application or extension. They’re looking for apps that show off the most productivity in a business as well as apps that use extensions in a unique, innovative way. &lt;/p&gt;  &lt;p&gt;Check out the &lt;a href="http://www.codeproject.com/Competitions/524/LightSwitch-Star-Contest.aspx"&gt;contest page on The Code Project&lt;/a&gt; for details. I can’t wait to see what you guys come up with. Good luck!&lt;/p&gt;  &lt;h4&gt;Sydney Lights it Up!&lt;/h4&gt;  &lt;p&gt;To kick off the LightSwitch launch in Australia, they lit up the Microsoft buildings on the waterfront with a cool light show that made the local news in Seattle! Watch the light show they did on YouTube: &lt;a href="http://youtu.be/OHw0T4fdkxQ"&gt;LightSwitch Launch on Sydney Waterfront&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;Notable Content this Month&lt;/h4&gt;  &lt;p&gt;Here’s some more of the fun things the team and community has released in October. &lt;/p&gt;  &lt;h6&gt;Extensions released in October (&lt;a href="http://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=VisualStudioVersion&amp;amp;f%5B0%5D.Value=VSLS&amp;amp;f%5B0%5D.Text=Visual%20Studio%20LightSwitch&amp;amp;sortBy=Popularity"&gt;see all 62 of them here!&lt;/a&gt;):&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/6a010249-4786-4d91-9aef-eda8ec474a9f"&gt;Because's Azure Tables for LightSwitch &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/126ecf80-70b2-463c-877f-c3c3426eadd2"&gt;Camera Image Control for LightSwitch &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/dd5fe416-2186-490f-945c-9a387a94bed5"&gt;CLASS Extensions &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/5b52c227-7bd4-48ba-90b0-376b52ea2eaa"&gt;LS2011 Simple Background Theme &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/10/06/metro-theme-updated.aspx"&gt;Metro Theme Updated!&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/222dd7af-04f1-4feb-b155-17afbf87700e"&gt;Minimal Shell &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/9c342bec-e3e5-4c08-9993-35ccb26d3c9f"&gt;Pixata custom controls for Lightswitch &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/5617c9a0-c8e9-4a63-b3fc-b0356dad430f"&gt;Spursoft LightSwitch Extensions &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/654f745f-eba9-45f7-ac1e-d23da173345a"&gt;Themes by Delordson (LightSwitchExtras.com) &lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Build your own extensions by visiting the &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh304488" target="_blank"&gt;LightSwitch Extensibility page&lt;/a&gt; on the &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;LightSwitch Developer Center&lt;/a&gt;. &lt;/p&gt;  &lt;h6&gt;Books:&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;New E-book published: &lt;a href="http://j.mp/qZvuOR"&gt;Developing Real-world Applications with LightSwitch&lt;/a&gt; by @gillcleeren &lt;/li&gt;    &lt;li&gt;New Book: &lt;a href="http://www.amazon.com/Microsoft-LightSwitch-Business-Application-Development/dp/1849682860#vs2010"&gt;Microsoft Visual Studio LightSwitch Business Application Development (now on Kindle&lt;/a&gt;) &lt;!--EndFragment--&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;Team Articles:&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;MSDN Magazine October Issue: &lt;a href="http://msdn.microsoft.com/en-us/magazine/hh456409.aspx"&gt;Securing Access to LightSwitch Applications&lt;/a&gt;       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/06/i-command-you-lightswitch-screen-commands-tips-amp-tricks.aspx"&gt;“I Command You!” - LightSwitch Screen Commands Tips &amp;amp; Tricks&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/10/03/advanced-lightswitch-writing-queries-in-lightswitch-code.aspx"&gt;Advanced LightSwitch: Writing Queries in LightSwitch Code&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/13/customizing-the-lightswitch-time-tracker-starter-kit.aspx"&gt;Customizing the LightSwitch Time Tracker Starter Kit&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/27/how-to-connect-to-and-diagram-your-sql-express-database-in-visual-studio-lightswitch.aspx"&gt;How to Connect to and Diagram your SQL Express Database in Visual Studio LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/10/11/how-to-create-a-ria-service-wrapper-for-an-editable-odata-source.aspx"&gt;How to Create a RIA Service Wrapper for an Editable OData Source&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/10/resources-from-silicon-valley-code-camp-lightswitch-sessions.aspx"&gt;Resources from Silicon Valley Code Camp LightSwitch Sessions&lt;/a&gt; &lt;!--EndFragment--&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;Community Articles:&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/65/CLASS-Extensions-Making-of-the-origins.aspx"&gt;CLASS Extensions. Making of (the origins)&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://bit.ly/pybGQX"&gt;Creating a Minimal LightSwitch Shell&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/64/Databinding-A-Complex-Multi-Table-Silverlight-Control-In-LightSwitch-ComponentOne-Scheduler.aspx"&gt;Databinding A Complex Multi-Table Silverlight Control In LightSwitch: ComponentOne Scheduler&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://janvanderhaegen.wordpress.com/2011/10/10/hacking-into-the-heart-of-a-lightswitch-application/"&gt;Hacking into the heart of a LightSwitch application&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://wp.me/p1kcLh-e1"&gt;LightSwitch: Change Default Database Instance&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://janvanderhaegen.wordpress.com/2011/10/10/looking-for-a-serviceproxy-usersettingsservice-alternative/"&gt;Looking for a ServiceProxy.UserSettingsService alternative&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/66/Using-The-Silverlight-DataGrid-With-LightSwitch.aspx"&gt;Using The Silverlight DataGrid With LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://janvanderhaegen.wordpress.com/2011/10/06/skinning-your-lightswitch-application-intro/"&gt;Skinning your LightSwitch application: intro&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/63/Silverlight-RichTextBox-Integrating-A-Control-That-Does-Not-Have-a-Dependency-Property-In-LightSwitch.aspx"&gt;Silverlight RichTextBox: Integrating A Control That Does Not Have a Dependency Property In LightSwitch&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;Videos &amp;amp; Podcasts:&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/10/12/how-do-i-create-custom-search-screens-in-lightswitch-beth-massi.aspx"&gt;How Do I: Create Custom Search Screens in LightSwitch? &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/archive/2011/10/19/video-how-do-i-handle-database-concurrency-issues-beth-massi.aspx"&gt;How Do I: Handle Database Concurrency Issues?&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/17/lightswitch-tips-amp-tricks-on-dnrtv.aspx"&gt;LightSwitch Tips &amp;amp; Tricks on dnrTV&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://bit.ly/tgifqc"&gt;Shop Down Under: Episode 73 - Andrew Coates Lights it up with LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://community.visual-basic.it/AlessandroEnglish/archive/2011/10/13/My-new-video-starting-migrating-an-Access-database-to-Visual.aspx"&gt;Start migrating an Access database to Visual Studio LightSwitch&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h6&gt;Samples (&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh204519"&gt;see all of them here&lt;/a&gt;):&lt;/h6&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/LightSwitch-Consuming-Web-c54979e0"&gt;LightSwitch - Consuming Web Services &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/LightSwitch-Metro-Theme-b1bfce24"&gt;Metro Theme Updated!&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Events Coming Up&lt;/h4&gt;  &lt;p&gt;Here some conferences and events I know about coming up soon that have LightSwitch presence. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://devconnections.com/shows/fall2011/sessions.aspx?s=178"&gt;DevConnections Las Vegas&lt;/a&gt; -&amp;#160; 10/31- 11/3 &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/acoat/archive/2011/10/07/lightswitch-and-azure-around-australia-in-october-and-november.aspx?ocid=soc-n-apac-mba--"&gt;LightSwitch and Azure Around Australia – &lt;/a&gt;Perth 11/2, Sydney 11/10 &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=459&amp;amp;mid=49"&gt;South Bay.NET User Group&lt;/a&gt; – 11/3 &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.componentone.com/SuperPages/Webcasts/?webcastID=204"&gt;LightSwitch Onramp &lt;/a&gt;– 11/10 &lt;/li&gt;    &lt;li&gt;&lt;a href="http://communitymegaphone.com/ShowEvent.aspx?EventID=4610"&gt;Louisville .NET Meetup&lt;/a&gt; – 11/17 &lt;/li&gt;    &lt;li&gt;&lt;a href="http://bit.ly/sqiHTs"&gt;The Power of LightSwitch on Windows Azure&lt;/a&gt; – Wellington 11/16 , Auckland 11/17 &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;LightSwitch Team Community Sites&lt;/h4&gt;  &lt;p&gt;And of course don’t forget the &lt;a href="http://msdn.com/lightswitch"&gt;LightSwitch Developer Center&lt;/a&gt;!&lt;/p&gt;  &lt;p&gt;This is your one-stop-shop to training content, samples, extensions, documentation, podcasts, a portal to the forums, community, and much more. All of the team content is aggregated onto this site, and we also aggregate all the community submitted extensions and samples. It’s the first place you should go if you’re just learning LightSwitch. &lt;/p&gt;  &lt;p&gt;Also here are some other places you can find the LightSwitch team: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823"&gt;LightSwitch “How Do I” Videos&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/category/vslightswitch"&gt;LightSwitch MSDN Forums&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/lightswitch"&gt;LightSwitch Team Blog&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://www.facebook.com/vslightswitch"&gt;LightSwitch on Facebook&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://twitter.com/#!/VSLightSwitch"&gt;LightSwitch on Twitter&lt;/a&gt; (@VSLightSwitch, #VisualStudio #LightSwitch) &lt;/p&gt;  &lt;h4&gt;Join Us!&lt;/h4&gt;  &lt;p&gt;The community has been using the hash tag #LightSwitch on twitter when posting stuff so it’s easier for me to catch it. &lt;a href="http://twitter.com/#!/search/realtime/%23LightSwitch"&gt;Join the conversation!&lt;/a&gt; And if I missed anything please add a comment to the bottom of this post and let us know!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10231806" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Community" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Community/" /><category term="Videos" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Videos/" /><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Books" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Books/" /><category term="Rollup" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Rollup/" /></entry><entry><title>Talking LightSwitch in the South Bay on Wednesday Nov. 2nd</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/28/talking-lightswitch-in-the-south-bay-on-wednesday-nov-2nd.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/10/28/talking-lightswitch-in-the-south-bay-on-wednesday-nov-2nd.aspx</id><published>2011-10-28T18:46:02Z</published><updated>2011-10-28T18:46:02Z</updated><content type="html">  &lt;p&gt;I’ll be speaking about LightSwitch next Wednesday in Mountain View so if you’re in the area come on out and I’ll show you what LightSwitch can do for you! See how to build business applications in light speed….&lt;/p&gt;  &lt;h2&gt;&lt;a href="http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=509&amp;amp;mid=49"&gt;Building Business Applications in Light Speed with Visual Studio LightSwitch&lt;/a&gt;&lt;/h2&gt;  &lt;p&gt;&lt;strong&gt;When: &lt;/strong&gt;Wednesday, 11/2/2011 at 6:00 PM    &lt;br /&gt;&lt;strong&gt;Where:&lt;/strong&gt; Hacker Dojo, 140A S Whisman Rd Mountain View, CA&lt;/p&gt;  &lt;p&gt;Visual Studio LightSwitch is the simplest way to build business applications for the desktop and cloud for developers of all skill levels. LightSwitch simplifies the development process by letting you concentrate on the business logic, while LightSwitch handles the common tasks for you. In this demo-heavy session, you will see, end-to-end, how to build and deploy a data-centric business application using LightSwitch. You will also see how professional developers can enhance the LightSwitch experience by tapping into its rich extensibility model. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.baynetug.org/DesktopModules/DetailXEvents.aspx?ItemID=509&amp;amp;mid=49"&gt;Register here.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Hope to see you there!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10231173" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Speaking" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Speaking/" /><category term="Community" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Community/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /></entry><entry><title>How to Connect to and Diagram your SQL Express Database in Visual Studio  LightSwitch</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/27/how-to-connect-to-and-diagram-your-sql-express-database-in-visual-studio-lightswitch.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/10/27/how-to-connect-to-and-diagram-your-sql-express-database-in-visual-studio-lightswitch.aspx</id><published>2011-10-27T14:08:00Z</published><updated>2011-10-27T14:08:00Z</updated><content type="html">&lt;p&gt;&lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;Visual Studio LightSwitch&lt;/a&gt; makes it easy to create and model database tables using the &lt;a href="http://msdn.microsoft.com/en-us/library/ff851993.aspx" target="_blank"&gt;Data Designer&lt;/a&gt;. With this designer you have a simple interface into the Tables, Columns and Relationships that make up your data model. When you create tables this way, under the covers LightSwitch creates a SQL Express database file at design time. SQL Express is installed with Visual Studio LightSwitch and is required for it to work properly. When you are ready to deploy your application you can choose to deploy it to any version of SQL Server, including SQL Azure, however during development time the LightSwitch development environment manages your database through SQL Express. We call this the &lt;em&gt;Intrinsic Database.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Many folks have asked me how I created the &lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/13/customizing-the-lightswitch-time-tracker-starter-kit.aspx" target="_blank"&gt;database diagram in the last article I wrote&lt;/a&gt; and I&amp;rsquo;ve seen the question in other Visual Studio forums as well. All versions of Visual Studio (not just LightSwitch) allow you to connect to SQL Server from the &lt;strong&gt;Server Explorer &lt;/strong&gt;window. This allows you to browse the tables and data. However getting the diagramming support to work is somewhat of a mystery for folks so in this post I&amp;rsquo;ll show you how you can get it to work on your local development machines.&lt;/p&gt;
&lt;p&gt;PLEASE NOTE: This technique requires you be an administrator of your machine and you installed Visual Studio (and thus SQL Express) under that administrator login. This technique should only be used for development environments.&lt;/p&gt;
&lt;h3&gt;Connecting to the Server Explorer&lt;/h3&gt;
&lt;p&gt;To connect to the intrinsic database open the Server Explorer (Ctrl+Alt+S).&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1731.image_5F00_2.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0741.image_5F00_thumb.png" width="357" height="309" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then right-click on the Data Connections and select &amp;ldquo;Add Connection&amp;hellip;&amp;rdquo; to add a new connection.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2620.image_5F00_42.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3884.image_5F00_thumb_5F00_20.png" width="467" height="198" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We need to connect to a specific database file on disk, not an attached database. During development time LightSwitch creates what&amp;rsquo;s called a &lt;strong&gt;User Instance&lt;/strong&gt; database that is dynamically attached to the SQL Express service when it is accessed. This makes it possible for you to copy LightSwitch development solutions and samples from machine to machine and not lose any of the critical data information.&lt;/p&gt;
&lt;p&gt;So when the &amp;ldquo;Add Connection&amp;rdquo; dialog comes up click the &amp;ldquo;Change&amp;hellip;&amp;rdquo; button.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3480.image_5F00_6.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1830.image_5F00_thumb_5F00_2.png" width="453" height="181" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then change the data source to &amp;ldquo;Microsoft SQL Server Database File&amp;rdquo; and click OK.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2313.image_5F00_32.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5047.image_5F00_thumb_5F00_15.png" width="525" height="304" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now you need to specify the file location of the database. The database file is always named ApplicationDatabase and it is located in the &lt;span style="font-family: Courier New;" face="Courier New"&gt;\bin\Data&lt;/span&gt; folder under your solution. Select the ApplicationDatabase.mdf file and click OK.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2620.image_5F00_8.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4863.image_5F00_thumb_5F00_3.png" width="789" height="426" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Use Windows Authentication and click the Test Connection button. If it succeeds click OK. (If it doesn&amp;rsquo;t, make sure you are logged into the machine as the same administrator you used to install Visual Studio).&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8203.image_5F00_10.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1643.image_5F00_thumb_5F00_4.png" width="395" height="465" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now you can see all the internal tables that LightSwitch has created for you based on your model in the Data Designer.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4061.image_5F00_12.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2620.image_5F00_thumb_5F00_5.png" width="321" height="451" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The Server Explorer lets you make any number of changes to not only the data stored in the tables but also the structure (schema). &lt;strong&gt;BE CAREFUL &lt;/strong&gt;here. Any changes you make directly to the database structure WILL NOT automatically be reflected in your data model and you could break it. The Data Designer makes sure your changes to the model stay in sync with the database but if you modify the database outside the Data Designer all bets are off. You have been warned! :-)&lt;/p&gt;
&lt;h3&gt;Setting Up Diagramming Support&lt;/h3&gt;
&lt;p&gt;However there are other nifty things you can do in the Server Explorer like enter more records of data as well as create database diagrams. In order to create a database diagram expand the &amp;ldquo;Database Diagrams&amp;rdquo; node. You will be presented with the following dialog:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8686.image_5F00_14.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3465.image_5F00_thumb_5F00_6.png" width="502" height="206" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Click Yes and another dialog will be presented:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0576.image_5F00_16.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6521.image_5F00_thumb_5F00_7.png" width="500" height="178" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Click Yes again. If the message goes away you&amp;rsquo;re all set. However, a lot of times it&amp;rsquo;s not that easy. Usually an error message appears similar to the following:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5531.image_5F00_20.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4466.image_5F00_thumb_5F00_9.png" width="447" height="176" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In order to get diagramming support working, the owner of the database must be a local login and a valid db_owner, not a domain login like I am above. So in order to fix this we need to change the database owner to a local account. When Visual Studio installs SQL Express, the service logs on as NETWORK SERVICE. You can check this by going to Services (Windows Start, search &amp;ldquo;Services&amp;rdquo;) and looking at the SQLEXPRESS service entry.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2311.image_5F00_28.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8255.image_5F00_thumb_5F00_13.png" width="803" height="194" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So if we change the database owner to this login, the diagramming will work. Although you can do this in SQL Server Management Studio, it&amp;rsquo;s not installed out of the box with Visual Studio so I&amp;rsquo;m going to show you how to get this working without installing anything else. First go back to the &lt;span style="font-family: Courier New;" face="Courier New"&gt;bin\Data&lt;/span&gt; folder where your intrinsic database is located and make a copy (just in case :-)).&lt;/p&gt;
&lt;p&gt;Then grant the NETWORK SERVICE permissions to the folder, allowing Full Control. (Right click on the \Data folder, select properties, security tab, click the Add button, enter NETWORK SERVICE, OK, then check off Full Control.)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1727.image_5F00_34.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6136.image_5F00_thumb_5F00_16.png" width="425" height="543" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now we need to create a small SQL script to attach the database to the SQL Express service, change the owner and then detach it again. Open notepad and paste the following into a new text file, modifying the path to your database files.&lt;/p&gt;
&lt;pre class="code"&gt;USE master
GO
-- Change the path to your database files! 
-- Make sure the login that runs your SQLEXPRESS service (i.e. NETWORK SERVICE) has file access to this folder

CREATE DATABASE ApplicationData ON 
( FILENAME = N'C:\...\Projects\MyApplication\MyApplication\bin\Data\ApplicationDatabase.mdf' ),
( FILENAME = N'C:\...\Projects\MyApplication\MyApplication\bin\Data\ApplicationDatabase_log.ldf' )
FOR ATTACH
GO

ALTER AUTHORIZATION ON DATABASE::ApplicationData TO [NT AUTHORITY\SYSTEM]
GO

USE master
GO
EXEC master.dbo.sp_detach_db @dbname = N'ApplicationData'
GO&lt;/pre&gt;
&lt;p&gt;Save the file as C:\Temp\ChangeOwner.sql &amp;ndash; with the SQL extension. Next open an administrator command prompt.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0654.image_5F00_24.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0247.image_5F00_thumb_5F00_11.png" width="280" height="109" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;First close Visual Studio &lt;/strong&gt;in order to close all connections to the database file.&lt;strong&gt; &lt;/strong&gt;Then type the following to execute the script:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New;" face="Courier New"&gt;sqlcmd -S .\SQLEXPRESS &amp;ndash;i "C:\Temp\ChangeOwner.sql"&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;Creating a Diagram&lt;/h3&gt;
&lt;p&gt;Now that&amp;rsquo;s all done open up Visual Studio again and you should see the ApplicationDatabase still sitting in the Server Explorer. To connect just expand the database node and then right click on the Database Diagrams folder and select &amp;ldquo;Add New Diagram&amp;rdquo;. Everything should be working now.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2311.image_5F00_36.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6136.image_5F00_thumb_5F00_17.png" width="424" height="229" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When you add a new diagram it will ask you what tables you want to include. In a LightSwitch database all the tables that start with &amp;ldquo;aspnet_&amp;rdquo; as well as the &amp;ldquo;RolePermissions&amp;rdquo; are internal and related to the authentication &amp;amp; authorization system. They cannot be modified so you can omit these from your diagram.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7510.image_5F00_38.png"&gt;&lt;img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3806.image_5F00_thumb_5F00_18.png" width="499" height="392" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Click Add and the diagram will be generated based on the tables you chose.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3487.image_5F00_40.png"&gt;&lt;img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5037.image_5F00_thumb_5F00_19.png" width="723" height="697" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In order to save the diagram just close the window by clicking on the &amp;ldquo;X&amp;rdquo; on the tab and you will be prompted to save the diagram back to the database.&lt;/p&gt;
&lt;h3&gt;REMEMBER&lt;/h3&gt;
&lt;p&gt;Using the Server Explorer against your intrinsic LightSwitch database can be useful for entering data or generating diagrams but anytime you want to make changes to the actual structure/schema of your tables you MUST do that in the Data Designer otherwise you risk getting your model out of sync.&lt;/p&gt;
&lt;p&gt;I hope this helps not only LightSwitch users but also other Visual Studio users get diagramming support working on their databases.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10230403" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="SQL Server" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/SQL+Server/" /><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="Data" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Data/" /><category term="VS2010" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/VS2010/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /></entry><entry><title>LightSwitch Tips &amp; Tricks on dnrTV</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/17/lightswitch-tips-amp-tricks-on-dnrtv.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/10/17/lightswitch-tips-amp-tricks-on-dnrtv.aspx</id><published>2011-10-17T20:51:26Z</published><updated>2011-10-17T20:51:26Z</updated><content type="html">&lt;p&gt;Check it out, I’m back with the always entertaining &lt;a href="http://www.dnrtv.com/" target="_blank"&gt;Carl Franklin on dnrTV&lt;/a&gt; showing some tips and tricks you can use in your screens and queries. See how you can add command bars to any control, create custom search screens, pass parameters into queries, and fine-tune the layout of your screens. &lt;/p&gt;  &lt;h3&gt;Watch: &lt;a href="http://www.dnrtv.com/default.aspx?showNum=206" target="_blank"&gt;Beth Massi on Tips and Tricks in LightSwitch 2011&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;Here’s some links I’d like to share from the show:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;LightSwitch Developer Center&lt;/a&gt; &amp;amp; &lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823" target="_blank"&gt;“How Do I” videos&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh499661.aspx"&gt;How Do I: Create Custom Search Screens in LightSwitch?&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/08/04/how-to-create-a-multi-column-auto-complete-drop-down-box-in-lightswitch.aspx"&gt;How to Create a Multi-Column Auto-Complete Drop-down Box in LightSwitch&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/08/16/how-to-allow-adding-of-data-to-an-auto-complete-drop-down-box-in-lightswitch.aspx"&gt;How to Allow Adding of Data to an Auto-Complete Drop-down Box in LightSwitch&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/09/15/filtering-lookup-lists-with-large-amounts-of-data-on-data-entry-screens.aspx"&gt;Filtering Lookup Lists with Large Amounts of Data on Data Entry Screens&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/06/i-command-you-lightswitch-screen-commands-tips-amp-tricks.aspx"&gt;LightSwitch Screen Commands Tips &amp;amp; Tricks&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10226632" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Speaking" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Speaking/" /><category term="Community" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Community/" /><category term="Videos" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Videos/" /><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Screens" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Screens/" /></entry><entry><title>Customizing the LightSwitch Time Tracker Starter Kit</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/13/customizing-the-lightswitch-time-tracker-starter-kit.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/10/13/customizing-the-lightswitch-time-tracker-starter-kit.aspx</id><published>2011-10-13T14:07:00Z</published><updated>2011-10-13T14:07:00Z</updated><content type="html">&lt;p&gt;&lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;Visual Studio LightSwitch&lt;/a&gt; released with a set of &lt;a href="http://www.microsoft.com/visualstudio/en-us/lightswitch/starter-kits" target="_blank"&gt;7 Starter Kits&lt;/a&gt; that people can use as starting points for their own applications. You can download them or install them directly in Visual Studio LightSwitch using the Extension Manager. Take a look at &lt;a href="http://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Visual-Studio-Toolbox-LightSwitch-Starter-Kits" target="_blank"&gt;Robert Green’s Visual Studio Toolbox episode for more info&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;One of the Starter Kits is a Time Tracker application for tracking employee timesheets against projects they are working on. Here’s the data model:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/7801.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3286.image_5F00_thumb.png" width="417" height="456" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Employees enter multiple time entries onto their time sheets and a project is selected on each of the time entries. This week a blog reader asked how he could get a tally of all hours worked on a given project for a given employee. In this post I’ll describe how to create a screen that filters on project and employee and tallies all the time entries.&lt;/p&gt;  &lt;h2&gt;Creating the Parameterized Query&lt;/h2&gt;  &lt;p&gt;In order to do this we’ll need to create a parameterized query that optionally filters on Employee and Project. Right-click on the TimeEntries table in the Solution Explorer and select “Add Query”. Name it TimeWorked. Next we need to add a filter on the Project.Id “equals” then choose “@ Parameter” and add a new parameter called ProjectID. Do the same thing for the employee by expanding TimeSheet.Submitter and select Id “equals” another “@ Parameter”. This time add a new parameter called SubmitterID.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5165.image_5F00_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4263.image_5F00_thumb_5F00_3.png" width="169" height="383" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then select the SubmitterID parameter and in the property window check “Is Optional” to make that one an optional parameter. That way we can optionally see the total hours worked for a selected project across all our employees. Also add a sort by the SubmittedDate Descending. Your query should now look like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8054.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1033.image_5F00_thumb_5F00_4.png" width="510" height="364" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Create the Custom Search Screen&lt;/h2&gt;  &lt;p&gt;Next add a new search screen based on this query. Click the “Add Screen” button at the top of the query designer and choose the Search Data Screen template and select the TimeWorked query you just created for the Screen Data and click OK. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5734.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6811.image_5F00_thumb_5F00_5.png" width="799" height="573" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Notice that LightSwitch added screen fields for the filter criteria that needs to be fed into the query. However we don’t want users to have to type in IDs, instead we want a dropdown of choices for both Employee and Project. So delete the two fields on the view model on the left-hand side of the screen designer:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6646.image_5F00_14.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1524.image_5F00_thumb_5F00_6.png" width="526" height="393" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;When you delete these fields the controls in the content tree will also be removed. Next click the “Add Data Item” button at the top and add a Local Property of Type “Project (entity)” and name it “SelectedProject”, then click OK.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8468.image_5F00_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3175.image_5F00_thumb_5F00_7.png" width="510" height="509" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Do the same thing for Employee. Click the “Add Data Item” button again and add a Local Property of Type “Employee (entity)” and name it “SelectedEmployee”, then click OK. Now you should see Employee and Project in your view model. Drag them to the top of the content tree to place them above the results Data Grid. LightSwitch will automatically create drop-down controls for you.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2185.image_5F00_18.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3187.image_5F00_thumb_5F00_8.png" width="511" height="628" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The next thing we need to do is hook up the selected items to the query parameters. First select the ProjectID query parameter in the view model, then in the properties window set the binding to SelectedProject.Id:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3175.image_5F00_20.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0458.image_5F00_thumb_5F00_9.png" width="573" height="199" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Once you do this a grey arrow will indicate the binding on the far left. Do the same thing for SubmitterID and set the binding to SelectedEmployee.Id. &lt;/p&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h3&gt;Calculating Hours&lt;/h3&gt;  &lt;p&gt;The final piece of the screen we need is the tally of all the hours worked across the time entries that are returned based on our filter criteria. Click “Add New Data Item” once again and this time choose Local Property of Type Decimal, uncheck “Is Required” and call it TotalHours.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4744.image_5F00_26.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/0451.image_5F00_thumb_5F00_12.png" width="515" height="512" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now you will see the TotalHours field in the view model. Add it to the screen anywhere you want by dragging it to the content tree. In this example I’ll add it above the results grid. Make sure to change the control to a Label. You can also select how the label font appears by modifying that in the properties window. &lt;/p&gt;  &lt;p&gt;Last thing we need to do is calculate the total hours based on this filter. Anytime the TimeWorked query is successfully loaded we need to calculate the TotalHours. Select TimeWorked in the view model and then at the top of the screen drop down the “Write Code” button and select the “TimeWorked_Loaded” method. Write this code to tally the hours:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;TimeWorked_Loaded(succeeded &lt;span style="color: blue"&gt;As Boolean&lt;/span&gt;)
&lt;span style="color: blue"&gt;    Me&lt;/span&gt;.TotalHours = 0 &lt;br /&gt;    &lt;span style="color: blue"&gt;If &lt;/span&gt;succeeded &lt;span style="color: blue"&gt;Then
&lt;/span&gt;        &lt;span style="color: blue"&gt;For Each &lt;/span&gt;te &lt;span style="color: blue"&gt;In &lt;/span&gt;TimeWorked
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.TotalHours += te.HoursWorked
        &lt;span style="color: blue"&gt;Next
    End If
End Sub&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now run it! Once you select a project the query will execute and the total hours displayed for all employees that worked on the project. If you select an employee, the results will narrow down further to just that employee’s hours.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6327.image_5F00_28.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2526.image_5F00_thumb_5F00_13.png" width="742" height="560" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Starter kits are a GREAT way to get started with Visual Studio LightSwitch. I urge you to explore them and customize them for your exact needs.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10224217" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Screens" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Screens/" /><category term="Starter Kits" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Starter+Kits/" /><category term="Queries" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Queries/" /></entry><entry><title>Resources from Silicon Valley Code Camp LightSwitch Sessions</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/10/resources-from-silicon-valley-code-camp-lightswitch-sessions.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/10/10/resources-from-silicon-valley-code-camp-lightswitch-sessions.aspx</id><published>2011-10-10T20:45:33Z</published><updated>2011-10-10T20:45:33Z</updated><content type="html">&lt;p&gt;Thanks to &lt;a href="http://peterkellner.net/" target="_blank"&gt;Peter Kellner&lt;/a&gt; and all the folks that made for another extraordinary &lt;a href="http://www.siliconvalley-codecamp.com/" target="_blank"&gt;Silicon Valley Code Camp&lt;/a&gt; this year! There were over 2300 people that came to Foothill college in Los Altos this weekend. And what gorgeous weather we had!&lt;/p&gt;  &lt;p&gt;&lt;img src="http://blog.siliconvalley-codecamp.com/wp-content/uploads/2011/10/IMG_1612.jpg" width="219" height="164" /&gt;&amp;#160;&lt;img src="http://blog.siliconvalley-codecamp.com/wp-content/uploads/2011/10/IMG_1613.jpg" width="219" height="164" /&gt;&amp;#160;&lt;img src="http://blog.siliconvalley-codecamp.com/wp-content/uploads/2011/10/IMG_1583.jpg" width="218" height="165" /&gt;&lt;/p&gt;  &lt;p&gt;Thanks to all those folks who came out to my LightSwitch talks Saturday afternoon, I had a blast! Here are all the resources from the sessions to check out. Of course, all of these resources are available from the &lt;a href="http://msdn.com/lightswitch" target="_blank"&gt;LightSwitch Developer Center&lt;/a&gt;, including the &lt;a href="http://www.microsoft.com/visualstudio/en-us/lightswitch/try" target="_blank"&gt;free trial download&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;Intro Session: Building Business Applications Quickly with Visual Studio LightSwitch&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/lightswitch" target="_blank"&gt;Vision Clinic Walkthrough &amp;amp; Sample&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://go.microsoft.com/?linkid=9741442" target="_blank"&gt;LightSwitch Training Kit&lt;/a&gt; – See Demo: Introducing Visual Studio LightSwitch &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Advanced Session: LightSwitch Advanced Development and Customization Techniques&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.msdn.microsoft.com/Contoso-Construction-9f944948" target="_blank"&gt;Contoso Construction Sample&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh304488" target="_blank"&gt;Extending Visual Studio LightSwitch&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://go.microsoft.com/?linkid=9741442" target="_blank"&gt;LightSwitch Training Kit&lt;/a&gt; – See Lab: LightSwitch Control Extensions &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And here are some more good resources that you’ll want to explore as you start building your LightSwitch business apps!&lt;/p&gt;  &lt;h2&gt;Start&lt;/h2&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/library/ff852059.aspx"&gt;Create Your First LightSwitch Application&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ee256724.aspx"&gt;Tour the Development Environment&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/visualstudio/en-us/lightswitch/starter-kits"&gt;Download LightSwitch Starter Kits&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/gg604823"&gt;Watch the LightSwitch “How Do I” Videos&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Learn&lt;/h2&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff938857.aspx"&gt;LightSwitch Learning Center&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://go.microsoft.com/?linkid=9741442"&gt;LightSwitch Training Kit&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh204519"&gt;LightSwitch Samples&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Extend&lt;/h2&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=VisualStudioVersion&amp;amp;f%5B0%5D.Value=VSLS&amp;amp;f%5B0%5D.Text=Visual%20Studio%20LightSwitch"&gt;Browse Popular LightSwitch Extensions Online&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Community&lt;/h2&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.com/lightswitch"&gt;LightSwitch Developer Center&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-us/category/vslightswitch"&gt;Ask Questions in the Forums&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/b/lightswitch/"&gt;Read the LightSwitch Team Blog&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.facebook.com/vslightswitch"&gt;Become a LightSwitch Fan on Facebook&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://twitter.com/VSLightSwitch"&gt;Follow us on Twitter!&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10222944" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="Speaking" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Speaking/" /><category term="Community" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Community/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /></entry><entry><title>“I Command You!” - LightSwitch Screen Commands Tips &amp; Tricks</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bethmassi/archive/2011/10/06/i-command-you-lightswitch-screen-commands-tips-amp-tricks.aspx" /><id>http://blogs.msdn.com/b/bethmassi/archive/2011/10/06/i-command-you-lightswitch-screen-commands-tips-amp-tricks.aspx</id><published>2011-10-06T20:58:22Z</published><updated>2011-10-06T20:58:22Z</updated><content type="html">&lt;p&gt;In this post I wanted to pull together some command tips that seem common when building features into the screens in your business applications. Some of them are floating around on the LightSwitch forums, community blogs, and samples but I thought having these in one place would be easier for folks. I use these techniques a lot when I’m building my own LightSwitch applications. &lt;/p&gt;  &lt;p&gt;In this article I will show you:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="#command"&gt;How to Create a Command &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#screen"&gt;How to Open a Open Another Screen (with or without Parameters)&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#modal"&gt;How to Open a Modal Dialog or Window &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#browser"&gt;How to Open the Browser &amp;amp; Navigate to a URL &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#calc"&gt;How to Open the Calculator (or other Windows System Programs) &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#file"&gt;How to Open an “Open File” Dialog &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#program"&gt;How to Open the Default Program for a File (like Office Documents)&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So let’s get started!&lt;/p&gt;  &lt;h2&gt;&lt;a name="command"&gt;How to Create a Command &lt;/a&gt;&lt;/h2&gt;  &lt;p&gt;First off let me start by showing you what I mean by “screen commands”. Commands are buttons (or links) that users click to perform some sort of action.&amp;#160; You can add commands to any control like grids &amp;amp; textboxes as well as the screen itself. Take a look at the documentation &lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff852036.aspx"&gt;&lt;em&gt;How to: Add a Custom Command to a Screen&lt;/em&gt;&lt;/a&gt;. Commands show up in the model on the left-hand side of the screen designer and are indicated by the pink method icons. You always have three commands by default – Close, Refresh and Save. Refresh and Save also appear in the Screen Command Bar by default when running the application.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5481.image_5F00_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6567.image_5F00_thumb_5F00_1.png" width="537" height="425" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Creating commands has two main parts – creating the actual button (or link), then writing the code to execute the command in the &lt;em&gt;command&lt;/em&gt;_Execute method. (You can also control whether the command buttons are enabled or disabled by writing code in &lt;em&gt;command&lt;/em&gt;_CanExecute method.) Commands can be buttons or links and typically are located in the ribbon at the top of the screen (called the Screen Command Bar) as well as on Data Grids or topmost group controls (called Command Bar) and these are displayed by default when you create a screen. However, you can add commands to any control on a screen that you want so you have a lot of flexibility on the placement of your commands. Here is a screen with a variety of commands:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5824.image_5F00_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2671.image_5F00_thumb_5F00_5.png" width="773" height="592" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To add a command to the Screen Command Bar or Command Bar for a group just select it in the screen designer and click the +Add button. Depending on the control LightSwitch will present a set of pre-built commands. On group controls that display data from a single entity, you can add a prebuilt command “Delete” that will delete the current record. On data grids and lists that work with multiple entities you can select a from a variety of commands for adding, editing and deleting records. You can also overwrite the default behavior of these commands by right-clicking on them and selecting “Override Code”. &lt;/p&gt;  &lt;p&gt;To create a new custom command, select “New button” and then give it a method name. At that point it will appear in the model on the left of the screen designer. Once you create the button, right click on it and select “Edit Execute Code” to write the code for the command.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5700.image_5F00_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1106.image_5F00_thumb.png" width="649" height="391" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you don’t see a Command Bar on a control (like a label, textbox, date picker, autocomplete box, etc.) just right-click on the control and then on the menu you will see &amp;quot;Add Button…”. You can also click “Add Layout Item” at the top of the screen designer and select “Add Button…”. If you’re running the application in &lt;a href="http://msdn.microsoft.com/en-us/library/ff852030.aspx" target="_blank"&gt;screen customization mode&lt;/a&gt; then select the control and click the “Add button” icon &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5808.image_5F00_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2350.image_5F00_thumb_5F00_4.png" width="21" height="20" /&gt;&lt;/a&gt; at the top of the content tree. This gives you the flexibility to put commands anywhere on the screen you want. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5305.image_5F00_25.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/4745.image_5F00_thumb_5F00_8.png" width="380" height="310" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now that you understand how to create commands anywhere you want, here are some tips &amp;amp; tricks on some common code that you can write for your custom commands. Note that you can write this code in any of the screen methods, they are not limited to commands. Although that’s probably the most common place you will see custom code like this. &lt;/p&gt;  &lt;h2&gt;&lt;a name="screen"&gt;How to Open Another Screen (with or without Parameters)&lt;/a&gt;&lt;/h2&gt;  &lt;p&gt;This one is very common and very simple in LightSwitch. In order to open a screen you use the Application object to access all your screens and call one of the “Show&lt;em&gt;”&lt;/em&gt; methods.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;OpenMyScreen_Execute()
    &lt;span style="color: green"&gt;' Write your code here.
&lt;/span&gt;&lt;span style="color: blue"&gt;    Me&lt;/span&gt;.Application.ShowCreateNewCustomer()
&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can also define optional and required parameters on screens. For instance if we &lt;a href="http://msdn.microsoft.com/en-us/library/ff852069.aspx" target="_blank"&gt;create a screen based on a query&lt;/a&gt; that requires a parameter then LightSwitch will generate a screen field for us in the model that is used to feed the query. You can select this field and in the properties window you can indicate that it is a screen parameter as well as whether it is required or not. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8535.image_5F00_16.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/8032.image_5F00_thumb_5F00_7.png" width="889" height="482" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keep in mind that screens that have required parameters will not show up in the main navigation bar because they must be called in code. &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;OpenMyScreen_Execute()
    &lt;span style="color: green"&gt;' Write your code here.
&lt;/span&gt;&lt;span style="color: blue"&gt;    Me&lt;/span&gt;.Application.ShowSearchCustomersByPostalCode(&lt;span style="color: #a31515"&gt;&amp;quot;98052&amp;quot;&lt;/span&gt;)
&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;For a couple video demonstrations to see this in action please watch:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/ff961919"&gt;How Do I: Pass a Parameter into a Screen from the Command Bar in a LightSwitch Application?&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh301582"&gt;How Do I: Open a Screen After Saving Another Screen in a LightSwitch Application?&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;&lt;a name="modal"&gt;How to Open A Modal Dialog or Window&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;There are also a couple methods on screens that allow up to pop up modal message boxes and input boxes. To present a message to the user you write the following:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.ShowMessageBox(&lt;span style="color: #a31515"&gt;&amp;quot;This is the message&amp;quot;&lt;/span&gt;)&lt;/pre&gt;

&lt;p&gt;You can also specify a caption and what kind of buttons you want on the message box like OK, OK and Cancel, Yes and No, etc. ShowMessageBox will return a value that indicates what the user chose. In this example I am want to ask the user if they are sure they want to delete a record. Since Delete is a pre-built command, just right-click on it in the screen designer and select “Override Code”. Then you can write the following:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;gridDeleteSelected_Execute()
&lt;span style="color: blue"&gt;    If Me&lt;/span&gt;.ShowMessageBox(&lt;span style="color: #a31515"&gt;&amp;quot;Are you sure you want to delete this record?&amp;quot;&lt;/span&gt;,
                         &lt;span style="color: #a31515"&gt;&amp;quot;Delete&amp;quot;&lt;/span&gt;,
                         &lt;span style="color: #2b91af"&gt;MessageBoxOption&lt;/span&gt;.YesNo) = Windows.&lt;span style="color: #2b91af"&gt;MessageBoxResult&lt;/span&gt;.Yes &lt;span style="color: blue"&gt;Then

        Me&lt;/span&gt;.Customers.SelectedItem.Delete()
    &lt;span style="color: blue"&gt;End If
End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can also get input from the user by using an input box. This is handy for presenting a message and requesting a single answer from the user.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Search_Execute()
&lt;span style="color: blue"&gt;    If Me&lt;/span&gt;.CustomerPostalCode = &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot; &lt;/span&gt;&lt;span style="color: blue"&gt;Then
        Me&lt;/span&gt;.CustomerPostalCode = &lt;span style="color: blue"&gt;Me&lt;/span&gt;.ShowInputBox(&lt;span style="color: #a31515"&gt;&amp;quot;Please enter a postal code to search for:&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;Search&amp;quot;&lt;/span&gt;)
    &lt;span style="color: blue"&gt;End If
    Me&lt;/span&gt;.CustomersByPostalCode.Load()
&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can also open other modal windows that you create on the screen in the content tree. For instance, you may have a lot of fields on a record and you want to display the entire set of fields in a modal window when the user clicks a row command in a search screen instead of requiring them to scroll. Simply add the Selected Item to the bottom of your screen and then change the control type to a Modal Window. You can then lay out the fields exactly how you like. By default LightSwitch will create a button command for you to launch the modal window automatically but you can turn this off in the properties window by unchecking “Show Button”. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6404.image_5F00_22.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2843.image_5F00_thumb_5F00_10.png" width="574" height="660" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to launch this modal window from your own command you can call OpenModalWindow and pass it the Name of the Modal Window control:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;ShowAllFields_Execute()
&lt;span style="color: blue"&gt;    Me&lt;/span&gt;.OpenModalWindow(&lt;span style="color: #a31515"&gt;&amp;quot;Customers_SelectedItem&amp;quot;&lt;/span&gt;)
&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/1682.image_5F00_24.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5822.image_5F00_thumb_5F00_11.png" width="596" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This video also shows a couple of these techniques:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/lightswitch/hh301582"&gt;How Do I: Open a Screen After Saving Another Screen in a LightSwitch Application?&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;&lt;a name="browser"&gt;How to Open the Browser &amp;amp; Navigate to a URL&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;This is a common one for sure. Maybe you want to open a browser to a specific site, or a report from SQL reporting services, or a SharePoint site. For instance say we have a textbox for our website address field. We can add a command to the control and then execute code to open the address. First you will need to add a reference to the System.Windows.Browser assembly. On the Solution Explorer flip to file view and then right-click on the Client project and select Add Reference. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/6813.image_5F00_thumb12_5F00_thumb_5F00_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image_thumb12_thumb" border="0" alt="image_thumb12_thumb" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/3757.image_5F00_thumb12_5F00_thumb_5F00_thumb.png" width="545" height="358" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then on the .NET tab select System.Windows.Browser and then click OK.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/2768.image_5F00_20.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-81-88-metablogapi/5327.image_5F00_thumb_5F00_9.png" width="484" height="413" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then you’ll need to add these imports at the very top of your code file: &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;Microsoft.LightSwitch.Threading
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Runtime.InteropServices.Automation&lt;/pre&gt;

&lt;p&gt;Now you can write code to open a browser to a specific URL:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;OpenSite_Execute()
    &lt;span style="color: #2b91af"&gt;Dispatchers&lt;/span&gt;.Main.BeginInvoke(
        &lt;span style="color: blue"&gt;Sub&lt;/span&gt;()
            &lt;span style="color: green"&gt;'Dim uri As New Uri(&amp;quot;http://www.bing.com&amp;quot;) 'Go to a specific website
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;uri &lt;span style="color: blue"&gt;As New &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;(&lt;span style="color: blue"&gt;Me&lt;/span&gt;.Customer.WebSite) &lt;span style="color: green"&gt;'Go to website stored in the Customer.WebSite field

            &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;AutomationFactory&lt;/span&gt;.IsAvailable) &lt;span style="color: blue"&gt;Then
                Dim &lt;/span&gt;shell = &lt;span style="color: #2b91af"&gt;AutomationFactory&lt;/span&gt;.CreateObject(&lt;span style="color: #a31515"&gt;&amp;quot;Shell.Application&amp;quot;&lt;/span&gt;)
                shell.ShellExecute(uri.ToString)

            &lt;span style="color: blue"&gt;ElseIf &lt;/span&gt;(&lt;span style="color: blue"&gt;Not &lt;/span&gt;System.Windows.&lt;span style="color: #2b91af"&gt;Application&lt;/span&gt;.Current.IsRunningOutOfBrowser) &lt;span style="color: blue"&gt;Then
                &lt;/span&gt;System.Windows.Browser.&lt;span style="color: #2b91af"&gt;HtmlPage&lt;/span&gt;.Window.Navigate(uri, &lt;span style="color: #a31515"&gt;&amp;quot;_blank&amp;quot;&lt;/span&gt;)
            &lt;span style="color: blue"&gt;End If
        End Sub&lt;/span&gt;)
&lt;span style="color: blue"&gt;End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Notice that we need to make sure we always call this code from the Main UI thread. If you don’t you will get an error if you are running LightSwitch as a browser application. When running in desktop mode the AutomationFactory.IsAvailable is true so that means we need to open the default browser. If we are already in the browser, then we can simply navigate to a new page. &lt;/p&gt;

&lt;p&gt;You can also do a lot of other things in desktop mode like access the Windows file-system, open default programs, and use COM automation. Here’s some more tips for your desktop applications. &lt;/p&gt;

&lt;h2&gt;&lt;a name="calc"&gt;How to Open the Calculator (or other Windows System Programs)&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;This is based on a tip I saw from Paul Patterson that I thought was pretty clever: &lt;a href="http://www.paulspatterson.com/technology/lightswitch/microsoft-lightswitch-open-the-system-calculator-with-interop/" target="_blank"&gt;Open the System Calculator with Interop&lt;/a&gt;. This is a nice productivity feature for users working with numerical values on your screen. Just like the previous example that opens the browser, you can open any Windows system programs with ShellExecute in desktop mode (this will not work in browser mode). First add this import to the top of your code file:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Runtime.InteropServices.Automation&lt;/pre&gt;

&lt;p&gt;Then you can simply pass to ShellExecute the name of the Windows program you want to open:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;OpenProgram_Execute()
&lt;span style="color: blue"&gt;    Try
        If &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;AutomationFactory&lt;/span&gt;.IsAvailable) &lt;span style="color: blue"&gt;Then
            Dim &lt;/span&gt;shell = &lt;span style="color: #2b91af"&gt;AutomationFactory&lt;/span&gt;.CreateObject(&lt;span style="color: #a31515"&gt;&amp;quot;Shell.Application&amp;quot;&lt;/span&gt;)

            shell.ShellExecute(&lt;span style="color: #a31515"&gt;&amp;quot;calc.exe&amp;quot;&lt;/span&gt;) &lt;span style="color: green"&gt;'Open the calculator
            &lt;/span&gt;shell.ShellExecute(&lt;span style="color: #a31515"&gt;&amp;quot;notepad.exe&amp;quot;&lt;/span&gt;) &lt;span style="color: green"&gt;'Open notepad
            &lt;/span&gt;shell.ShellExecute(&lt;span style="color: #a31515"&gt;&amp;quot;mspaint.exe&amp;quot;&lt;/span&gt;) &lt;span style="color: green"&gt;'Open Paint
        &lt;/span&gt;&lt;span style="color: blue"&gt;End If

    Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Exception
        &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.ShowMessageBox(ex.ToString)

&lt;span style="color: blue"&gt;    End Try
End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;h2&gt;&lt;a name="file"&gt;How to Open an “Open File” Dialog&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;You may want to request a file from a user and you need to present the Open File Dialog. Here’s how you can do that. First add these imports to the top of your code file:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;Microsoft.LightSwitch.Threading
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Runtime.InteropServices.Automation
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows&lt;/pre&gt;

&lt;p&gt;Then write this code to open the Open File Dialog which prompts the user for a file:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Function &lt;/span&gt;GetFile(fileFilter &lt;span style="color: blue"&gt;As String&lt;/span&gt;) &lt;span style="color: blue"&gt;As &lt;/span&gt;IO.&lt;span style="color: #2b91af"&gt;FileInfo
&lt;/span&gt;&lt;span style="color: blue"&gt;    Dim &lt;/span&gt;file &lt;span style="color: blue"&gt;As &lt;/span&gt;IO.&lt;span style="color: #2b91af"&gt;FileInfo &lt;/span&gt;= &lt;span style="color: blue"&gt;Nothing

    &lt;/span&gt;&lt;span style="color: green"&gt;'This only works in desktop mode in LightSwitch.
    &lt;/span&gt;&lt;span style="color: blue"&gt;If &lt;/span&gt;&lt;span style="color: #2b91af"&gt;AutomationFactory&lt;/span&gt;.IsAvailable &lt;span style="color: blue"&gt;Then

        &lt;/span&gt;&lt;span style="color: green"&gt;'You need to open the file dialog on the main thread.
        &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Dispatchers&lt;/span&gt;.Main.Invoke(
            &lt;span style="color: blue"&gt;Sub&lt;/span&gt;()
                &lt;span style="color: blue"&gt;Dim &lt;/span&gt;dlg &lt;span style="color: blue"&gt;As New &lt;/span&gt;Controls.&lt;span style="color: #2b91af"&gt;OpenFileDialog
                &lt;/span&gt;dlg.Filter = fileFilter

                &lt;span style="color: blue"&gt;If &lt;/span&gt;dlg.ShowDialog = &lt;span style="color: blue"&gt;True Then
                    &lt;/span&gt;file = dlg.File
                &lt;span style="color: blue"&gt;End If
            End Sub&lt;/span&gt;)
    &lt;span style="color: blue"&gt;End If
    Return &lt;/span&gt;file
&lt;span style="color: blue"&gt;End Function&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Then you could use this to guide the user into opening certain types of files by specifying a filter. Keep in mind that you can read from any file on the local machine but you are limited to writing or accessing the full path or details of the file to only those that come from trusted locations like the user’s My Document folder.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;FindFile_Execute()
    &lt;span style="color: blue"&gt;Try
        &lt;/span&gt;&lt;span style="color: green"&gt;'Request a text file:
        &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;myFile = GetFile(&lt;span style="color: #a31515"&gt;&amp;quot;Text Files (*.txt)|*.txt&amp;quot;&lt;/span&gt;)
&lt;span style="color: green"&gt;
        'You can read from files anywhere on disk that the user has access to.
        ' However you can only write to files in trusted locations like My Documents.
        &lt;/span&gt;&lt;span style="color: blue"&gt;Using &lt;/span&gt;fs = myFile.OpenText()
            &lt;span style="color: blue"&gt;Me&lt;/span&gt;.ShowMessageBox(fs.ReadToEnd())
            fs.Close()
        &lt;span style="color: blue"&gt;End Using

        &lt;/span&gt;&lt;span style="color: green"&gt;'Try to get the full path to the file. This will throw a SecurityException if
        ' the file is not from a trusted location like My Documents.
        &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.ShowMessageBox(myFile.FullName)

    &lt;span style="color: blue"&gt;Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Security.&lt;span style="color: #2b91af"&gt;SecurityException
        &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.ShowMessageBox(&lt;span style="color: #a31515"&gt;&amp;quot;Please select a file in your Documents, Music or Pictures folder.&amp;quot;&lt;/span&gt;)

    &lt;span style="color: blue"&gt;Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Exception
        &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.ShowMessageBox(ex.ToString)
&lt;span style="color: blue"&gt;    End Try
End Sub&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Also note that in LightSwitch opening the OpenFileDialog will only work in Desktop applications which have elevated permissions. If you try to directly launch the OpenFileDialog in a browser-based application you will get a “Dialogs must be user-initiated” error message. This is because Silverlight dialogs (like OpenFileDialog) can only be opened from “user actions”, like a button clicked event handler. The reason why this won’t work with LightSwitch is because we invoke the button logic asynchronously, so the code is not considered to be “user-initiated”. For a work-around see the “&lt;em&gt;Add a Simple Silverlight dialog&lt;/em&gt;” section of Matt Sampson’s post: &lt;a href="http://blogs.msdn.com/b/rmattsampson/archive/2011/05/10/how-do-i-import-data-from-a-web-application.aspx" target="_blank"&gt;How Do I Import Data While Running a LightSwitch Web Application&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;&lt;a name="program"&gt;How to Open the Default Program for a File (like Office Documents)&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;If you want to open a file in it’s default program (specified by Windows) you can just use ShellExecute again. In this case you probably need to request the file from the user first so you can use the GetFile method in the previous tip above for that. Add these imports to the top of your code file:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;Microsoft.LightSwitch.Threading
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Runtime.InteropServices.Automation
&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Windows&lt;/pre&gt;

&lt;p&gt;Then you can write code like this to request the file and then open it with the default program. Here’s a couple examples:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;OpenFile_Execute()
&lt;span style="color: blue"&gt;    Try
        If &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;AutomationFactory&lt;/span&gt;.IsAvailable) &lt;span style="color: blue"&gt;Then
            Dim &lt;/span&gt;shell = &lt;span style="color: #2b91af"&gt;AutomationFactory&lt;/span&gt;.CreateObject(&lt;span style="color: #a31515"&gt;&amp;quot;Shell.Application&amp;quot;&lt;/span&gt;)

            &lt;span style="color: green"&gt;'Open a text file 
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;textFile = GetFile(&lt;span style="color: #a31515"&gt;&amp;quot;Text Files (*.txt)|*.txt&amp;quot;&lt;/span&gt;)
            shell.ShellExecute(textFile.FullName)

            &lt;span style="color: green"&gt;'Open an Excel file
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;excelFile = GetFile(&lt;span style="color: #a31515"&gt;&amp;quot;Excel Files (*.xlsx)|*.xlsx&amp;quot;&lt;/span&gt;)
            shell.ShellExecute(excelFile.FullName)

            &lt;span style="color: green"&gt;'Open a Word Document
            &lt;/span&gt;&lt;span style="color: blue"&gt;Dim &lt;/span&gt;wordFile = GetFile(&lt;span style="color: #a31515"&gt;&amp;quot;Word Files (*.docx)|*.docx&amp;quot;&lt;/span&gt;)
            shell.ShellExecute(wordFile.FullName)
        &lt;span style="color: blue"&gt;End If

    Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Security.&lt;span style="color: #2b91af"&gt;SecurityException
        &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.ShowMessageBox(&lt;span style="color: #a31515"&gt;&amp;quot;Please select a file in your Documents, Music or Pictures folder.&amp;quot;&lt;/span&gt;)

    &lt;span style="color: blue"&gt;Catch &lt;/span&gt;ex &lt;span style="color: blue"&gt;As &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Exception
        &lt;/span&gt;&lt;span style="color: blue"&gt;Me&lt;/span&gt;.ShowMessageBox(ex.ToString)
    &lt;span style="color: blue"&gt;End Try
End Sub
&lt;/span&gt;&lt;/pre&gt;

&lt;h2&gt;Wrap Up&lt;/h2&gt;

&lt;p&gt;I hope this post showed you some cool tips and tricks you can use on your screens and commands. Remember that you can put commands anywhere on your LightSwitch screens and there are a good set of prebuilt commands you can use for working with data. However if you need to provide users additional productivity features you can easily create custom commands and do almost anything you want. &lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10221305" width="1" height="1"&gt;</content><author><name>Beth Massi</name><uri>http://blogs.msdn.com/bethmassi/ProfileUrlRedirect.ashx</uri></author><category term="DevCenter" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/DevCenter/" /><category term="Article" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Article/" /><category term="LightSwitch" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/LightSwitch/" /><category term="Screens" scheme="http://blogs.msdn.com/b/bethmassi/archive/tags/Screens/" /></entry></feed>
