LightSwitch Entity Designer – Seeing “The Big Picture”

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.

AddNewProject

ClassLibrary

In this class library add an ADO.NET Entity Data Model item

ApplicationDataModel

Choose “Generate from Database” and then “Add New Connection”.

GenerateFromDatabase

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:

NewConnection

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.

ChooseTables

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…”

 

UpdateModel

  • Lloyd Derbyshire

    Very cool Jewel. Thank you for your clear and concise instructions. I was able to use this with a simple Visual Studio 2012 LightSwitch HTML Client project I’ve been playing with. It worked as advertised. There is no higher praise than that. As you say, especially with a large number of tables, having this relationship view can save your sanity. A dream come true.

    • Jewel Lambert

      That’s great to hear, Lloyd – the world needs its developers (mostly) sane :)

  • virtualCableTV

    I’m glad I tried this with a test project as one false step (apparently forgot to load app and update intrinsic in between testing updating the modal when adding and deleting columns) and it wiped out the entire database object after a mapping error.

    Loses connection with the entire database. Even FUBAR when using SSM Studio to validate connection, table and data. Typical voodoo.

    Be careful when running with these scissors…