Chapter 1. Introducing Visual Studio LightSwitch

Computers have revolutionized everyday life, especially our work lives within the business world. Organizations have increasingly adopted computers and business applications for a number of reasons. For example, computers allow businesses to store huge amounts of data. They also allow the automation of many different tasks, thus reducing both time required to complete a task/process and the monetary expense involved. Although often still necessary, paper use has decreased significantly over the years, being replaced by digital documents. Employee tasks have been optimized and sped up, and one single person can do more work now than before office automation.

Computers, which are the hardware, are nothing without the software. Software falls into hundreds of categories, but the special one that helps companies solve their business problems is known as business applications. There are different kinds of business applications: At the highest level, business applications can be both general purpose, such as programs that can be used by different companies in a same category, and specific to the needs of one company, such as programs developed in house or commissioned to external software houses.

Business applications have always adapted to changes in technology. To understand that, all you have to do is just compare business applications made to run on MS-DOS with modern business applications that run on Microsoft Windows 7 or on the Web. But today, there is also another problem: On one hand, business moves at the speed of light, and technologies must follow the evolution of business requirements; on the other hand, jobs are more dynamic, and so one person might have to embrace multiple roles within the organization. During all its history, Microsoft has always paid close attention to organizations’ businesses and needs, and has built complete applications for the office while also offering development tools that programmers could use to build a variety of high-quality applications customized for company needs. But if business influences technologies, the opposite is also true, because technology (by offering modern data platforms and models) can seriously influence how companies organize their life. From the developer perspective, modern applications can really make the difference from several points of view:

• Improved user experience

• Robust data platforms

• Scalability

• Cloud computing

• Collaboration

Microsoft has always played an important role in the evolution of technology and of development tools. To combine all the most modern technologies and business requirements, including the ease of application use and development, Microsoft has created a new, straightforward development environment called Visual Studio LightSwitch. As you discover in this book, LightSwitch is not just a replacement for previous popular business application tools. Instead, it simplifies the development of modern business applications based on the most recent technologies, including the desktop, the Web, and the cloud. Visual Studio LightSwitch is a great tool for several reasons that you will discover throughout this book. The following list identifies a few of these reasons:

• It focuses on the business requirements. Therefore, you write code focusing on your business logic only; LightSwitch takes care of the rest of the code for you.

• It makes building business applications dramatically easy and quick. This is what you might be interested in if you are new to development or if you are not an expert (and you do not need to become one eventually).

• It is built on the shell of Microsoft Visual Studio 2010, and so you’ll find it familiar if you have spent some time with this development environment. In addition, applications that you build with LightSwitch use the latest technologies from Microsoft. The biggest benefit is that the developer does not need to learn all of them because LightSwitch puts them all together for you.

This chapter introduces you to Microsoft Visual Studio LightSwitch, providing basic information about its main features and about the technologies that it uses. From this, you will get a sense of the overall development environment. Then, starting in Chapter 2, “Exploring the IDE,” you get your hands dirty as a programmer.

Before we start talking about Visual Studio LightSwitch, it is important to review the most important development tools that Microsoft has released over the years for building business applications. By taking this detour through history, you will better understand what led Microsoft to create Visual Studio LightSwitch, what problems it solves, and why this new tool can really make the difference in terms of productivity and modernity.

Who Uses LightSwitch?

Put succinctly, Visual Studio LightSwitch is a tool for developers. LightSwitch users generally fall into the following categories:

• Developers with little experience (or absolute beginners)

• Expert developers who do not have time to waste and who want (or need) to be productive quickly

• Small companies or departments that want to build internal line-of-business applications quickly that respond to specific business requirements

• Developers who do not have deep knowledge of the most recent technologies from Microsoft but who need to adhere to new requirements such as cloud computing or interacting with SharePoint web portals

• Employees with some computer experience who have been asked to start building departmental applications

• Developers with experience on Microsoft Visual Basic (VB) 6, Visual Basic for Applications (VBA), Access, or FoxPro who must migrate to the .NET technologies rapidly and with the smallest effort possible

Such a wide variety of users can use Visual Studio LightSwitch because it guides them through the process of creating modern, scalable business applications, while allowing deep customizations and access to the underlying framework if needed.

A Short History of Microsoft Business Tools

Over the years, Microsoft has created several important and very popular tools for building business applications. Of these, some are still in use by many developers around the world; others have been discontinued. These tools cover a variety of scenarios and are dedicated to different audiences, including both the novice and expert developers, and are for both single users and for enterprises. This section recaps the most important business tools that Microsoft has released in the Windows era. From this review, you will come to understand what has been missing in modern software (and thus the benefits of LightSwitch) as you read about the advantages and disadvantages of these various tools.


Note for Absolute Beginners

This section provides a detailed overview of Microsoft business development tools over the years. This is useful to better understand how LightSwitch fits today in the world of business applications. If you are uninterested in understanding this evolution, however, you can skip this section. After all, the biggest benefit of LightSwitch is that you can build powerful applications without knowing what is going on under the hood.


Microsoft Access with Visual Basic for Applications

Microsoft Access is probably the most popular tool for building data-centric applications using a back-end database, especially for single-user workstations. With Microsoft Access, users can build data-centric applications quickly, based on a simple approach: tables + forms = applications. The several benefits of Access include the following:

• It is included in the Microsoft Office suite, meaning that a company that purchased this set of applications can also take advantage of a tool that works with databases.

• Because of its deep integration with other Office applications, importing data from and exporting data to other tools (such as Microsoft Excel) is easier.

• It supports custom queries and one-to-many relationships.

• It allows building convenient user interfaces that make it easier to enter and query data from the database.

• Portability is enhanced. Databases created with Microsoft Access can be shared easily because everything (including data and pieces of the user interface) is included in a single .mdb or .accdb file. In addition, users are not limited to use the database within Access. In fact, custom applications can interact with Access databases via specific data providers, like the one provided by the .NET Framework.

• It simplifies the development of building business applications because the user just needs to create the database and its structure (tables and columns); next, the user designs forms for interacting with data via a simple user interface. Microsoft Access is then responsible for data-binding tables to the appropriate elements in the user interface, such as controls like TextBox, Label, and so on.

With particular regard to the last point in the list, Access has another benefit: It allows customizing the data-binding experience and building more sophisticated forms by adding buttons, ActiveX controls, custom actions, and control panels. It is also not uncommon that users enter data into the Access database by simply writing information to tables, without building any forms. The popularity of Access is a result of these key elements, and it should not surprise you that Microsoft still invests in this tool, as demonstrated by the new version available in Office 2010. Figures 1.1 and 1.2 show examples of Microsoft Access in action, both while designing tables and while entering data.

Image

Figure 1.1. Designing and populating a table in Microsoft Access 2010.

Image

Figure 1.2. A data entry form in Microsoft Access.

Like other applications in the Microsoft Office suite, Access allows complex customization via developers writing VB code and supports a special version of the Visual Basic programming language known as Visual Basic for Applications (VBA), which is dedicated to Office automation. Many developers use VBA to add advanced functionality to business applications built with Access, and it is important to underline that VBA is quite similar to VB 6, described in the next subsection. That said, Microsoft Access has a number of drawbacks and does not fit well in some business scenarios for the following reasons:

• It is good for single users, but it has poor support for multiuser environments.

• As a consequence of the previous point, Access databases are not the best choice when working within networks; this also limits the possibilities of building robust web applications (although using Access databases on the Web is allowed).

• Only limited management of permissions and users is possible.

• It has great integration with the rest of the Microsoft Office applications, but very poor integration with other technologies such as the .NET Framework and its ecosystem.

• The maximum allowed size for an Access database is 2GB. If you consider that SQL Server 2008 R2 Express Edition (which ships for free) allows a maximum size of 10GB per database, the contrast is stark.

• It does not produce executable files; therefore, unless you build a custom application that connects to an Access database via an external data provider, you cannot use a business application built with Access if you do not have this application installed on your machine.

• It is not natively supported by most modern data-access technologies, such as the ADO.NET Entity Framework.

• There is a very limited support for logging and tracing information.

Generally speaking, Microsoft Access is a great tool that both novices and experienced users can leverage, but its use should be limited to specific scenarios like single users working on discrete sets of data.

Microsoft Visual Basic 6

Microsoft Visual Basic (VB) 6 is one of the most successful programming languages and development tools in history. First released in 1998, it is still one of the most used tools for building applications across the world. VB 6 is a general-purpose programming language, meaning that it is not expressly dedicated to developing data-centric applications, but it can be used for building a variety of software for Windows and the Web, including business, entertainment, and games. The popularity of VB 6 results from several reasons:

• It is an easy-to-learn programming language, much simpler than other programming languages.

• It enables users to build a plethora of different kinds of applications, particularly modern (for that time) Win32 applications.

• It offers a Rapid Application Development (RAD) environment that makes it easier to create applications via visual tools.

• It improves code writing thanks to a primitive version of the IntelliSense technology.

• It facilitates the creation of Windows applications via several wizards that allow automating the code generation for both the imperative code and the user interface.

• Continuing from the previous point, it makes the data access simpler via the Microsoft ADO and DAO providers and via specific data visualization controls (such as the famous MSHFlexGrid). In addition, VB 6 introduced a simplified data-binding approach based on wizards that generates all the code and the pieces of user interface required in data entry forms.

• It enables users to build reusable components, such as type libraries and ActiveX controls.

Figure 1.3 shows VB 6 in action.

Image

Figure 1.3. The Microsoft Visual Basic 6 development environment.

From a programming language point of view and from the perspective of the technologies it can take advantage of, VB 6 has the following limitations:

• Although it is currently one of the most-used application development programs in the world, it shipped in 1998. So, Microsoft is encouraging customers to upgrade to modern, supported versions.

• It produces executable files based on the COM architecture. Although interoperability between COM and the .NET architecture is possible, the interoperability results in performance penalties and complexities. So, in many cases, you cannot take advantage of the modern technologies available via the .NET Framework.

• It offers limited support for the object-oriented programming. VB 6 is generally an event-oriented programming language.

• There is no support for building 64-bit applications. Applications built with VB 6 can run on 64-bit operating systems, but they are executed in the 32-bit layer of the operating system (also known as WoW, Windows on Windows).

• As with other programming languages from that period, it requires hundreds of calls to the Windows API functions for common interactions with the operating system and manual management of system resources and memory.

• Interacting with code produced by developers using other languages is quite difficult (in contrast to what happens today in the .NET Framework).

• Although VB 6 enables you to create web applications, the way VB 6 facilitates building websites is obsolete. With VB 6, you can create classic ASP websites, but there is no support for different platforms prominent on the Web today.

• It does not offer multithreading support. In addition, pointer management is really difficult.

• It was created for operating systems based on older architectures. VB 6 applications often encounter problems when running on Microsoft Windows Vista or Microsoft Windows 7 (especially because of the User Access Control feature).

Of course, these limitations must be considered in a modern application development context. Thousands of developers bravely decided to abandon VB 6 when .NET Framework 1.0 was released, and lots of others have moved to .NET since then. However, thousands of developers still work on VB 6, but they are failing to fully exploit recent technologies from Microsoft and other companies that the .NET platform makes straightforward. This also dramatically limits the business scenarios that are available to .NET developers. Think of rich Internet applications (Microsoft Silverlight), data access based on object models (ADO.NET Entity Framework), and rich client applications (Windows Presentation Foundation [WPF] ). These are just a few examples of modern technologies that perfectly meet the requirements of the IT world today but that VB 6 cannot match. Obviously, in some situations, business applications are perfectly fine remaining on VB 6 (for example, applications that do not need modern technologies to solve problems they were built to solve). In such cases, investing in migration can be too expensive. Considerations change, however, if these applications are meant to be upgraded over the years; the cost of maintaining these applications over time can be the real business driver for upgrading to the .NET technologies.

Microsoft Visual FoxPro

Microsoft Visual FoxPro is another popular, specialized development tool for creating business applications built upon databases. Visual FoxPro is a powerful RAD environment that ships with its own database engine but that also allows connecting to external data sources, such as Microsoft SQL Server. In contrast to Microsoft Access, Visual FoxPro enables users to create standalone Win32 executables that can take advantage of reusable components such as ActiveX controls. Visual FoxPro is neither a tool intended for end users nor a tool for beginners (as Access is for the latter). In fact, Visual FoxPro requires knowledge of programming fundamentals because it is actually a procedural, data-centric, and object-oriented programming language whose syntax has some commonalities with SQL. The latest version of Visual FoxPro is 9.0, shipped back in 2004 and which is supported until 2015. However, Microsoft decided that it will not enhance Visual FoxPro, but the community is extending it.

Figure 1.4 shows what the development environment looks like.

Image

Figure 1.4. The development environment in Microsoft Visual FoxPro 9.

FoxPro provides an easy way for users to design forms that are data-bound to tables and columns. Basically, after you have your data structure, you can easily create the user interface by taking advantage of the built-in wizards. In addition, the whole development experience can be extended by writing code. This is a great environment because it also allows interactions with Microsoft Office, XML data sources, web services, and client/server architectures. Although powerful, Visual FoxPro has some constraints:

• You must be a developer with a good knowledge of programming concepts and fundamentals. Visual FoxPro is powerful but not easy to use. In addition, it supports programming concepts like classes, inheritance, and events (another reason why it is not simple for the beginner developer or the inexperienced employee who wants to create a database for his or her company’s purposes).

• Like VB 6, it produces applications based on the COM architecture. Therefore, it cannot take advantage of all the magic possible in a .NET environment.

• Although some programming concepts are common, sharing skills between VB 6 and Visual FoxPro is somewhat difficult.

• Like VB 6, applications created with Visual FoxPro might encounter problems when running on Windows Vista and Windows 7.

• Users cannot create web applications (not even in classic ASP).

For many years, Visual FoxPro has played an important role in the development of business applications, but Microsoft is encouraging customers to upgrade to .NET technologies.

Microsoft Visual Studio .NET (2002 to 2010)

Microsoft Visual Studio has always represented the state of art in development tools. Starting from 2002, Microsoft released the .NET Framework and new versions of Visual Studio based on this technology. The latest version, Visual Studio 2010, is the most powerful development environment ever and ships with a full set of tools that help developers build and deploy high-quality, scalable, and fast applications for multiple platforms. It provides a great code editor, now based on WPF technology, but the environment is not just about writing code. It comes with a plethora of professional tools (including the debugger, the profiler, code analyzer, testing tools, and so on) that accompany the developer throughout the whole application development life cycle. Although it is not possible here to explain all the features in the .NET Framework, the following are the most important benefits:

• It is a new layer between the operating system and applications that takes care of managing memory and system resources on behalf of the developer.

• It ships with a great base class library that wraps almost all the Windows API and that offers them under the form of managed classes and procedures. Because of the huge number of classes and functions proposed, developers seldom have to “reinvent the wheel.”

• It is the common runtime infrastructure for the most modern technologies (for example, client, web, and cloud technologies such as WPF, Silverlight, ASP.NET, and Windows Azure).

• It includes the command-line compilers and runtime libraries for all the .NET programming languages for free (a revolutionary first for Microsoft). Basically, you can create the most complex .NET applications with just Windows Notepad (although that would rarely happen) and then compile it for free.

• Programming languages in the .NET family (typically Visual Basic, Visual C#, and Visual F#) rely on the Common Language Runtime, which provides a common set of libraries and runtime components that produce the same intermediate code, whatever programming language you use. This intermediate code is then translated on-the-fly into a classic executable when you run the application. This dramatically simplifies interaction with code and components written by other developers, eventually in different programming languages. This also has another advantage: If you learn one of the .NET programming languages, you can use the other ones; you just need to learn a different syntax, not a different underlying technology or runtime.


Microsoft Visual Studio Express Editions

Starting from version 2005, Microsoft released the Visual Studio Express editions. These are lightweight, full-featured editions of the development environment for single programming languages expressly dedicated to students, hobbyists, and novice developers. These editions are free and can be used to build commercial applications. Although the IDE offers fewer functionalities than professional editions (the .NET Framework), languages and compilers are exactly the same.


Visual Studio 2010 is the perfect environment for building applications for modern operating systems, such as Windows Vista, Windows 7, and Windows Server 2008 R2 (including 64-bit applications). In addition, it simplifies application development with a number of built-in project templates that cover every possible area, including the desktop, the Web, and the cloud, and it supports the most advanced technologies from Microsoft, such as WPF, Silverlight, Windows Azure, and ASP.NET. It allows building multiple executable files in one solution, such as applications and libraries, built with different programming languages and for different platforms. It is an extensible environment that can be enriched with additional components built not only by Microsoft but also by other developers. Data providers included in the .NET Framework can connect to different data sources, such as Microsoft SQL Server, Microsoft Access, Oracle databases, and ODBC data sources. With regard to the development of business applications, Visual Studio .NET has always helped developers by offering the so-called drag-and-drop data binding, which makes it easy to bind the user interface to data sources by automating the generation of code that makes this possible. Recently, in Visual Studio 2010, support for drag-and-drop data binding has been added to WPF and Silverlight projects, too. Figure 1.5 shows what Microsoft Visual Studio 2010 looks like.

Image

Figure 1.5. Microsoft Visual Studio 2010 in action.

Microsoft put into Visual Studio 2010 very powerful tools for building business, data-centric applications via specific tool windows, data providers, user controls, and objects from the base class library. Visual Studio 2010 is probably the perfect tool for building high-quality, professional, data-centric applications but this statement requires some clarification. Visual Studio and the .NET programming languages are general-purpose instruments for creating a huge variety of applications, including rich media, entertainment, games, websites, and so on. Therefore, although Visual Studio 2010 is a great environment for building business applications, it is not all about data access. Moreover, creating data-centric applications in Visual Studio 2010 for the .NET Framework involves writing a lot of code (often complex) and requires knowledge of data-access technologies such as LINQ, the ADO.NET platform, or the ADO.NET Entity Framework, and then it requires knowing how the data binding works. As a consequence, creating applications with Visual Studio 2010 and the .NET Framework 4 is often not easy. You need to know at least one programming language, and you need to know in detail the most important concepts of programming. In other words, Visual Studio 2010 (and previous .NET versions) enables users to build all types of applications with all the flexibility that the developer needs, but it is up to the developer to make the right decisions about both technologies and techniques to use (which also requires writing all the necessary code). With regard to business applications, however, common patterns occur frequently, and the building of modern and scalable applications requires moving as fast as the business does. This is where Visual Studio LightSwitch comes in!

About Visual Studio LightSwitch

Microsoft realized that developers needed a modern development environment expressly dedicated to the creation of business applications based on the .NET Framework and that could run on both modern client operating systems and on the cloud. They determined that such a tool should combine the simplicity of Microsoft Access and the complexity of VB 6 and Visual FoxPro, but focus on today’s business requirements (such as the capability to work with a variety of data providers) and target the most recent technologies. With these requirements in mind, Microsoft developed Visual Studio LightSwitch. This is a new product in the Visual Studio 2010 family that makes building line-of-business applications simpler than ever. With Visual Studio LightSwitch (or simply LightSwitch), you can create modern and robust business applications for the desktop, the Web, and the cloud quickly and easily, even without writing a single line of code. Just to give you an idea of what you can do with LightSwitch, Figures 1.6 and 1.7 show two instances of an application in action.

Image

Figure 1.6. A data entry screen in an application built with Visual Studio LightSwitch.

Image

Figure 1.7. A complex search form in an application built with LightSwitch.

Figures 1.6 and 1.7 show how modern the user interface is for LightSwitch applications. These screenshots also show a number of features, such as screen navigation, data validation, paging, exporting to Microsoft Excel, and functionalities for data interaction. The great news is that all this plumbing is implemented by LightSwitch, and you do not need to write a single line of code to get it in the box. As a consequence, you do not need to be an experienced developer to create data-centric applications with LightSwitch, because the logic behind this tool is very simple: data + screens = application. The underlying logic is that most line-of-business applications combine two elements at their core: data sources and data entry screens. So, LightSwitch focuses on this rather than on writing code. In theory, you could build a LightSwitch application without even knowing what programming is. But if you are an experienced developer, you can leverage your existing skills with the .NET technologies to provide deep customizations on the applications you create. LightSwitch offers a convenient designer for defining your data and ships with a number of built-in screen templates so that you do not need to waste your time in creating the user interface; you just use built-in templates and bind them to your data. Visual Studio LightSwitch solves a number of problems, including the following:

• It targets modern scenarios, such as recent client operating systems (Windows Vista, Windows 7, Windows Server 2008 and 2008 R2) and cloud systems like Windows Azure.

• Applications run on the .NET Framework, so their architecture is robust.

• One application can be built to run on the desktop or inside a web browser, and this choice is accomplished with a single click.

• It combines simplicity and complexity in one development environment so that it can be used by both inexperienced and expert developers.

• As you learn later in this book, applications built with LightSwitch embed a lot of features by default, such as validation, paging, and data-bound forms, so that they can be created with the smallest effort possible.

• From the developer perspective, it allows focusing on writing only the code you actually need, which is the business logic.

• It works with databases, but it is not limited to this and can aggregate data from different sources, like SharePoint 2010 and Windows Communication Foundation (WCF) RIA Services.

• It is built upon the shell of Visual Studio 2010 and integrates deeply with Professional, Premium and Ultimate editions of this environment so that you can take advantage of professional tools for managing the entire application life cycle.

As covered later in this book, the developer must essentially make just one decision when creating a LightSwitch application: choosing the programming language, which can be Visual Basic or Visual C#. This does not imply that the developer will have to write code anyway. Instead, LightSwitch generates all the code required for the application by using the selected language. This choice will, of course, influence the application development if you want to extend the project with custom code.

Technologies Used Behind the Scenes

Visual Studio LightSwitch produces high-quality, scalable applications built upon the most recent technologies from Microsoft. Understanding which technologies empower LightSwitch applications behind the scenes is actually optional, especially if you are a developer who needs to build applications quickly and eventually without writing code, but becomes important when you want to make applications grow and when you want to understand the whys of certain behaviors. If you are instead an expert developer, it can be interesting for you to know which technologies are used in version 1.0 of LightSwitch so that you can maximize your leverage of them. This section describes all the technologies and architectural patterns that LightSwitch applications rely on.

This section summarizes all the technologies that LightSwitch utilizes to provide a complete vision of the advantages offered by the new development environment. They are not discussed in detail here because a deep discussion would require more than one book and because additional information about each technology is provided where appropriate throughout the rest of this book.

Runtime Components

Both the development environment and applications generated by LightSwitch are 100% .NET applications built upon the .NET Framework 4.0 and written with either Visual Basic or Visual C#. This provides the best runtime infrastructure that also takes care of system and memory management for you. More specifically, in version 1.0 LightSwitch generates applications built upon Silverlight 4.

Microsoft Silverlight is the very popular cross-browser, cross-platform, and cross-device plug-in for web browsers that enables developers to build rich Internet applications capable of aggregating multimedia and complex data management features in one place. Silverlight 4 is the heart of LightSwitch applications, and at the core it brings into LightSwitch a huge number of features that you know already if you have experience in Silverlight development. Among these features, the following are the most important:

Out-of-browser functionality: Although Silverlight applications are architected to run inside a web browser, with this feature they can be executed as desktop clients.

Data connections: Silverlight 4 allows connecting to data sources in a way that is usual in .NET projects.

Data-binding and data validation: Silverlight 4 provides a full-featured framework for binding data sources to the user interface, no matter where they are exposed from; also, Silverlight 4 makes it easy to validate data, thanks to specific properties available in data visualization controls.

Data paging: Silverlight 4 offers specific controls that make it really easy to page data, for better performances with very little effort.

Full trust and COM interoperability: Silverlight 4 introduces full trust permissions for out-of-browser applications so that it can take advantage of COM interoperability with local applications, such as Microsoft Office.

Communications: Silverlight 4 can leverage the most recent technologies from Microsoft for data exchange. This simplifies the way of building n-tier applications, with specific regard to the web server layer.

SQL Server: The Database Engine

With regard to the second point in the preceding list, it is important to understand that applications built with Visual Studio LightSwitch use Microsoft SQL Server Express Edition as the data store.

Microsoft SQL Server is the premier relational database management system from Microsoft.

The server-side database engine is known as a SQL Server instance, and databases based on this technology are referred to as SQL Server databases. Although this book does not focus on SQL Server and therefore it is not possible to describe its features in detail, such a database engine offers lots of advantages, including the following:

Single- or multiuser: It allows multiple simultaneous connections from computers within a network, but it can also be installed locally and consumed from within single workstations. So, it is the best choice in multiuser environments because databases can be accessed by multiple clients concurrently. The typical scenario is when a database is available on one company’s server and employees work with it concurrently.

Security: It offers the best support possible for user authentication to connect to databases, by including both Windows authentication and SQL authentication. Windows authentication retrieves credentials from the user who logged in to the operating system, whereas SQL authentication requires specifying a username and a password.

Management features: It provides interesting management features. For example, you can decide whether a user can or cannot access the database or what kind of information the user will be able to read, write, or both according to the role the user belongs to.

Strongly typed columns: Each column within a table is of a specific type, such as strings, numbers, dates, and so on. For each type, you have a number of choices to customize the column to your requirements (for example, ensuring that a string is shorter than 50 characters).

Data validation: If the information sent to the database is not compliant with the database requirements, that information is rejected.

Programmability: Developers and database administrators can interact with SQL Server databases via a special syntax of the Structured Query Language (SQL) known as Transact-SQL (or just T-SQL) and the SQL Native Client library, which is the bridge that provides access to databases to external technologies such as ADO.NET.

Transactions and concurrency: With transactions, changes to the database are saved permanently only if the sequence of commands completes successfully, whereas on failures, transactions allow reverting back to a consistent state. SQL Server also allows managing concurrency problems, which can occur when multiple clients attempt to save changes on the same piece of data concurrently.

Backup and recovery: With these features, you can easily automate backups for your data and later recoveries.

Scalability: The engine is capable of scaling tasks over CPUs and memory dynamically.

Clustering: If a SQL Server fails to serve a request, another SQL Server takes over the first one to complete it.

Logging, reporting, and analysis: Tools included in SQL Server allows keeping track of successful/failed logins, generating reports, and analyzing the database.

SQL Server is available in different editions, each targeting a particular audience (Enterprise, Developer, Express). Visual Studio LightSwitch uses the Express Edition, which is a lightweight version of the engine and which ships for free, meaning that you can use it in your company with commercial purposes. LightSwitch supports SQL Server 2008, 2008 R2, and 2005; when you install the development tools, SQL Server 2008 R2 Express is installed by default. You can get detailed information about SQL Server from the official website from Microsoft: www.microsoft.com/sqlserver/en/us/default.aspx.


Supported Editions of SQL Server

Visual Studio LightSwitch enables you to work with SQL Server Express Edition as the data store. This is an important thing to remember because it enables you to work with a database engine that ships for free and that you can use in your company with very few limitations (such as the limit of 10GB per database). However, SQL Server Express is also a requirement for development. So, if you have an instance of SQL Server Developer Edition on your development machine, LightSwitch will not recognize it and you will have to install the Express Edition. You definitely will be able to use other editions of SQL Server after you deploy your applications to production. This will be reprised in a specific discussion in this book and explained in more detail.


Communications

LightSwitch applications communicate with the data store passing through the WCF RIA Services, a specific implementation of the WCF technology dedicated to Silverlight 4. RIA Services make it easier to build n-tier applications and offer a complete infrastructure for handling operations against data, including queries and CRUD (create, read, update, and delete) operations. LightSwitch also uses an intermediate platform in communications, Internet Information Services (IIS), which is utilized when building 3-tier applications. IIS is a web server whose purpose is making information available through the Internet or through a local intranet and can also be installed locally for development purposes (see the “Setting Up the Development Machine” section, later in this chapter). Actually, IIS is a prerequisite only if you want to deploy applications as 3-tier clients, not as 2-tier clients.

Available Editions

Visual Studio LightSwitch ships as a single install that can run either as a standalone environment or as an add-on for Visual Studio 2010 Professional or higher. When running standalone, LightSwitch offers a complete environment for building business applications and offers all you need to be productive quickly. Installing LightSwitch as an add-on for Visual Studio 2010 brings you more power because it extends all the potential of Visual Studio to LightSwitch applications. In addition, this choice is required in particular situations, such as building custom controls, so it should be preferred when possible. This book focuses on the standalone edition by default. In those cases where Visual Studio 2010 is required, this is specified explicitly.

Companion Source Code

All the code examples explained in this book are available in both Visual Basic 2010 and Visual C# 4 source projects from this book’s website. In the printed book, however, code examples are explained in VB only. This is done so that developers who have previous experience with VB 6, Microsoft Access, and VBA can get up to speed more quickly with Visual Studio LightSwitch.

Setting Up the Development Machine


Installing Lightswitch

This chapter assumes you have already installed Visual Studio LightSwitch. For information about doing so, see Appendix A, “Installing and Configuring Visual Studio LightSwitch.”


To develop business applications with Visual Studio LightSwitch and to complete the code examples provided in this book, you need to satisfy a number of system and software requirements that are described in this section. Some of them are optional, but it is strongly recommended that you install every component for a complete development experience and understanding of the concepts described in this book.

Operating System

Microsoft Windows 7 (Professional or higher) is the preferred choice as the client operating system on your development machine. Visual Studio LightSwitch also runs on Windows Vista and Windows XP with Service Pack 3, but in this book, all the examples are explained on Windows 7. Most of the examples work on Windows 7 Home Premium, too, but an advanced configuration of IIS could be required. You instead need a server operating system, such as Windows Server 2008 or Windows Server 2008 R2, to complete the process of deploying LightSwitch applications to a web server. Chapter 10, “Deploying LightSwitch Applications,” provides examples based on Windows Server 2008 R2. However, this book also covers deploying to Windows Azure; if you do not have a web server running Windows Server 2008 or 2008 R2, this can be a good option for small businesses.

Development Environment

As mentioned previously, Visual Studio LightSwitch is available as both a standalone install and as an add-on for Visual Studio 2010 Professional or higher. In most cases, the standalone environment is enough for this book, but there are some chapters in which Visual Studio 2010 Professional or higher is required, with LightSwitch installed as an add-on. In particular, you need Visual Studio 2010 to complete Chapter 13, “Advanced LightSwitch with Visual Studio 2010,” Chapter 16, “Customizing Applications with Custom Controls,” Chapter 18, “LightSwitch Extensibility: Themes, Shells, Controls, and Screens,” and Chapter 19, “LightSwitch Extensibility: Data and Extension Deployment.”

Server Components

Visual Studio LightSwitch also requires a number of optional server components, such as IIS and SharePoint 2010. These are described in the following subsections.

Internet Information Services

One of the biggest benefits of Visual Studio LightSwitch is that it simplifies the development of n-tier applications. LightSwitch enables you to build both 2-tier and 3-tier applications. If you want to build a 3-tier application, you need to install and configure IIS on your machine. For Windows 7, go to Control Panel, Program and Features, Turn Windows Features On or Off and select all the development, security, and management features of the IIS item. On Windows Server 2008 R2, IIS is available as a role in your server that you must enable via the Server Manager. Notice that IIS is also required if you plan to use SharePoint 2010 as an external data source on your development machine.

SharePoint 2010

As you learn in detail in Chapter 8, “Aggregating Data from Different Data Sources,” Visual Studio LightSwitch can retrieve data from several data sources; among the available data sources, lists from SharePoint 2010 play an important role. Therefore, you need to connect to a machine where SharePoint 2010 is installed to test how this works (although optional). If you do not have the possibility of connecting to an existing instance of SharePoint 2010, you can install SharePoint 2010 Foundation on your development machine for testing purposes. The Foundation edition is a lightweight edition of SharePoint 2010 that enables developers to build a test environment over SharePoint 2010 (but one that cannot be used in production). You can download SharePoint 2010 Foundation for free from http://bit.ly/d31XDK.


Sharepoint 2010 Foundation’s Requirements

SharePoint 2010 Foundation can be also installed on client operating systems such as Windows 7 and Windows Vista with Service Pack 2. In this particular situation, this can be done only for development and testing purposes, not for production. In addition, installing SharePoint 2010 requires, as a general rule, a 64-bit operating system and at least 4GB of RAM.


Database Tools

As mentioned previously, when you install Visual Studio LightSwitch, the setup also installs Microsoft SQL Server 2008 R2 Express Edition as the database engine. This is a required component that hosts applications’ databases. By the way, it is helpful to install a management tool such as SQL Server 2008 R2 Management Studio Express Edition, which allows management of the database engine. In Management Studio, you can create and drop databases, edit tables, manage users and security permissions, manage authentication, and so on. You can also use it to build database diagrams (as covered in Chapter 4, “Building More-Complex Applications with Relationships and Details Screens”). If you do not have SQL Server Express Edition already on your machine, the LightSwitch setup will install the management console for you; otherwise, you must install it manually. If you need to do so, you can download SQL Server Management Server Express Edition (SSMSEE) from http://bit.ly/i2Rpmx.

Databases in the Cloud: SQL Azure

As mentioned at the beginning of this chapter, another benefit of development with Visual Studio LightSwitch is the capability to build applications that work in the cloud. Among the external data sources that Visual Studio LightSwitch can connect to, SQL Azure is the relational database in the cloud that makes possible hosting the application data in Microsoft data centers across the world, based on the Windows Azure Services Platform. Of course, this book describes this particular scenario in detail (see Chapter 8), but SQL Azure is a paid service. So, you need a subscription to the Windows Azure Services Platform to activate your SQL Azure space. There are several ways to subscribe the Windows Azure Services Platform, such as buying an MSDN subscription or paying only for the usage. This is a good option for small businesses that do not want to maintain their own server. Chapter 8 assumes you have a Windows Azure subscription, but it is certainly optional. Go to www.WindowsAzure.com and www.SqlAzure.com for more information and read carefully what Microsoft says about the paid services in this modern cloud-computing platform.

Controls and Toolkits

If you want to customize or otherwise add more complexity to the LightSwitch application examples described in this book, download and install some additional controls and toolkits that Microsoft releases for free. In particular, you might want to download the following:

Silverlight Toolkit, an open source project from CodePlex: http://silverlight.codeplex.com

Bing Maps control: http://tinyurl.com/32opzsf

LightSwitch Training Kit: http://bit.ly/hv1KXj

All of them can be considered optional because they require Visual Studio 2010 Professional or higher and, consequently, will be used only when this particular kind of environment is required.


Visual Studio Lightswitch Developer Center

Do not forget to visit the official Visual Studio LightSwitch Developer Center from Microsoft: http://msdn.com/lightswitch. This portal offers tons of learning resources, such as online documentation, code examples, “How-do-I” videos, and shortcuts to the latest blog posts and forum threads about LightSwitch.


What You Need to Know About Programming

Writing business applications with Visual Studio LightSwitch is an awesome experience. After all, you can build fully functional software without writing a single line of code, and you can also customize the application’s behavior by using the most advanced programming techniques that you already know about the .NET Framework. This book thoroughly covers both scenarios, but it does not explain the basics of programming for the .NET Framework or the syntax of the Visual Basic and Visual C# programming languages, except where specifically required. The reason is that such topics require more than one book. If your goal is just building simple line-of-business applications with minimal code, things are quite easy for you. However, you will not be able to take advantage of a lot of advanced features when developing with Visual Studio LightSwitch, including several scenarios covered in this book (such as building custom controls, writing custom queries, or building a reporting engine), and that might be important if your applications grow. (After all, Visual Studio LightSwitch is a tool for developers.) The goal of this book is to show how to write code focusing on the business logic, without having to understand how the .NET Framework works. In some circumstances, however, you are guided through the writing of more-complex code; with regard to this, this book assumes that you are familiar with concepts such as object-oriented programming, classes, modules, properties, methods, events, and how the .NET Framework works. If not, you should read a more specific book about programming before going on with LightSwitch. You might be interested in Visual Basic 2010 Unleashed by the author of this book or C# 4 Unleashed by Bart de Smet, both from Sams Publishing.

Summary

Visual Studio LightSwitch is a new development tool from Microsoft for rapidly building line-of-business applications for the desktop and the cloud, based on the .NET Framework 4. With Visual Studio LightSwitch, you can create data-centric applications easily and quickly with minimal code writing or you can customize applications by writing custom, complex code. This chapter provided an overview of Visual Studio LightSwitch, explaining what business problems it seeks to solve, especially as compared to previous development environments such as Microsoft Access, VB 6, and Visual FoxPro or to the complexity of Visual Studio 2010. After you have finished setting up your development machine, you are ready to start your new developer life with Visual Studio LightSwitch.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.74.3