As I mentioned in my previous post, I’ll be using the Chinook Database for this series. Chinook provides a nice set of tables dealing with music, each with non-trivial data and non-trivial relationships (as shown below):
It’s not quite an ERP system, but it’s not as small or overused as some of the others I’ve mentioned. I’m running SQL Server 2008 Express, but you could use MySQL, Oracle, SQL Server Compact Edition, or the XML File to the same end.
Back in Visual Studio, the Silverlight Business Application template created a solution with 2 projects. These are the client-tier and middle-tier for our RIA app as a Silverlight project and a Web project respectively. One of the major goals of RIA is to simplify development of n-tier applications, and so these 2 projects attempt to share as much as possible. As a .NET developer, it’s great to have the capability to reach many operating systems and browsers with your Silverlight apps, and it’s a great advantage to have many of the same classes and programming techniques available on the server side. RIA seeks to leverage this to your benefit (and to mine.)
These projects are organized to provide guidance about where classes are intended to be added without being too prescriptive or too complex, as shown below:
While it might not be immediately obvious, the ORM classes are intended to go in the Models folder of server side project (i.e., TwelveDaysOfRia.Web.) RIA is designed to be database and ORM agnostic, but Visual Studio 2010 makes it very nice to work with the SQL Server Entity Framework for this purpose. I built a model by adding a new item to the (server side) Models folder using the ADO.NET Entity Data Model template
which then asked me to choose whether I’d be generating my model from a database or would like an empty model (I chose to create from a database):
I then created a database connection, using SQL Server authentication. You can use integrated authentication quickly and easily here as well, and it works just fine through the entire stack. Be careful to remove the sensitive information from the connection string and consider switching to integrated authentication before going live with any such app.
I then added all the tables in the Chinook database to the model.
That gives me plenty to work with, and provides a nice master -> details -> details relationship to browse with Artists, Albums, and Tracks. There are others that will be nice to use as possible value lists (like Genre and MediaType) and still others that will have write activity (like Customer, Invoice, and InvoiceLine.)
The next step is the build a service that exposes the entities in this model to the client tier, and that will be the subject of my next posting.
Code for Day 2 is posted here.