# Silverlight 4 and WCF RIA Services generated from OlivaNova model

> Generate Silverlight 4 and WCF RIA Services from OlivaNova models. Model-driven approach to rich client applications.

*Published October 21, 2010* · Categories: net, mda, mdsd, microsoft, olivanova, silverlight

Source: https://www.kimpel.com/2010/10/21/silverlight-4-and-wcf-ria-services-generated-from-olivanova-model/


As stated in a [recent post](/post/silverlight-4-wcf-ria-services-and-olivanova-business-logic), I've been able to create a Silverlight 4 client that accesses an _OLIVA**NOVA**_ generated business logic using WCF RIA Services.

Well, the actual code to enable this scenario is in fact not that complicated (once you learned how to write Silverlight enabled WCF RIA Services). The big advantage for me is that the complete business logic can be generated with _OLIVA**NOVA**_'s model driven software development approach.

Basically, the code for the DomainService is pretty straight forward and also quite repetitive. Likewise, the XAML within the Silverlight project. So, it was pretty obvious to me that this peace of code could be also generated from the _OLIVA**NOVA**_ model.

I started by creating a new Visual Studio project. To keep it really simple, I created a new ASP.NET website. This application takes the _OLIVA**NOVA**_ model and the target client namespace as an input. Please see the screenshot below:

![Silverlight 4 application generated from OlivaNova](https://cdn.kimpel.com/clipboard024.gif)

After clicking on the _OK_ button, this application reads in the information from the model. The desired information I need is basically all the classes along with all their atttributes. Based upon this information, I then generate the following code:

- all entities or rather business objects as plain _C#_ classes.This contains some constructors and all attributes as properties. For the properties I add some standard attributes from _System.ComponentModel.DataAnnotations_. These attributes include a _Key_ indicator (primary key of that entity) as well as the _Display_ attribute (order of appearance and alias for the user interface).
- all _DomainService_ classes (WCF RIA Sercices). As a first step I only generate one service per entity that retrieves all data from this entity. Again, I make heavy usage of the _OLIVA**NOVA**_ generated framework code in order to access the business logic.
- a Silverlight XAML page per entity. The XAML basically contains the _DomainDataSource_ along with a _DataGrid_ and a _DataPager_. A _DomainContext_ (specified in the _DomainDataSource_) references the corresponding _DomainService_.
- all Silverlight code-behind files for the XAML page. This code actually does not do much more but setting the title of the page to its alias (information from the model).

The last step is then to copy all business object and _DomainService_ source code to the _BusinessApplication.Web_ project. All XAML and code-behind files will be copied to the _BusinessApplication_ project (underneath the _Views_ folder). I then referenced some of the newly generated views in the _MainPage.xaml_ and tested the Silverlight client.

What else could be generated based on information in the _OLIVA**NOVA**_ model?

- the menu or rather navigation of the Silverlight application
- the user interface in more detail (columns in the DataGrid, Master/Detail, service forms to create data)
- DomainService code to get related data (i.e. if I have a relationship between _Employee_ and _ExpenseReport_, I am able to call a method to retrieve all expense reports for a certain employee)
- basically all DomainService code for CRUD functionality (Create Read Update Delete)
- ...
- much more, if you put some more thought into this

Please have a look at some sample screenshots below to see the generated Silverlight client at runtim:.

![Employee](https://cdn.kimpel.com/employee.gif)

![ExpenseLine](https://cdn.kimpel.com/expenseline.gif)

