For rapid development of database-oriented applications, the Entity Designer built in to LightSwitch is very convenient. It makes it easy to add new entities, properties, and relationships. However, one thing lacking is a “model overview” that lets you see all of your entities and relationships in a single diagram.
If your application is very small and simple, and contains only a few tables, this may not matter much to you. But once you’re dealing with medium-sized data applications that may have a hundred or more tables, being able see the potentially complex relationships between your many tables can be very helpful. Indeed, as the number of tables grows, you can benefit from having multiple distinct data models, each focusing on a related group of tables (e.g. General Ledger, Scheduling, Accounts Receivable, etc.)
Visual Studio provides a nice modeling tool for use with Entity Framework – it can provide this missing feature to your LightSwitch projects.
Making use of it is quite simple:
First, run your LightSwitch Application at least once (otherwise the Intrinsic database may not have been created).
Add a new class library to your solution. I prefer to have a class library that will just be used to keep design/modeling artifacts for my project.
In this class library add an ADO.NET Entity Data Model item
Choose “Generate from Database” and then “Add New Connection”.
Establish a SQL Server connection with server name (localdb)v11.0 (careful – note that it’s a backslash and not a forward slash) and pick your LightSwitch project’s database from the “Select or enter a database name” drop-down:
Choose which tables you want to include in this model. Note that you can have as many separate Entity Data Models in your Class Library as you like, so if you have many tables, you may wish to group them into separate models instead of creating a single giant one.
Now you’re done – you’ve got a nice diagram of your tables, properties, and relationships. While you can move tables around in the diagram, add notes, and the like, you should treat this diagram as a “read only view” on your database schema. The LightSwitch Entity Designer is where you need to make any real changes (adding/changing/deleting entities, properties, or relationships).
Whenever you do make changes to the database schema in the LightSwitch Entity Designer, you can update your data diagram easily. First, run the application (to ensure that the intrinsic database has been updated to reflect the changes from the Entity Designer). Next, right-click on the ADO.NET Entity Data Model design surface and choose “Update Model from Database…”