web 2.0

III. EF Model as a starting point of development

Doménový model

EF Data model

If you are familiar with MDA, then you would maybe welcome this scenario, where you create a PIM and PSM with source code are then generated according to specified technology and platform.

However, Entity Framework is not about UML modelling of PIM, but has features to easily create entities, associations and inheritance between them in .NET solutions.

You are able to generate DDL schema for database you choose and C# or VB code of entities is generated, as well. So you can look on EF as an OR/M solution, as a tool to create your Data Model or to be a starting point for Domain Model with specific domain/business logic implemented in partial classes.

This post belongs to RIA Services MVVM Prism LoB Application series, read Introduction post to find out more about it.

In my application I chosen Entity Framework as a Data Access Layer (also because I wanted to test its capabilities comparing to Linq2Sql). I was partly influenced also by stronger support of EF in domain service and metadata generation in WCF RIA Services.

You can create you model in two ways: either from scratch or from database. In my case, I didn’t want to create the database schema first, but actually I wanted to check how well the SQL DDL generation works.

Creating the model is similar to creation of UML Class Diagram. Inheritance works the same way, but I had to face a problem with some specific associations. Fortunately, message in the result was quite explainful, so I overcame all of these problems.

Here is the data model of my demo RIA LoB application:

EF Data Model

EF Data Model

Have a look at the SQL DDL query generated from my EF Data Model. What I appreciate the most is, that the query is pretty human readable :-)

We tend to separate parts of our solutions to separate projects, but keep in mind, that if you put a domainservice in a different project that your EF model is located, the checkbox to generate metadata will be disabled.

I reccommend to either create metadata on your own (its not difficult, but rather bothersome work) or to create domainservice in the model’s project with generated metadata and copy the domainservice afterwards to a new project.

The other thing you have to decide is, whether you want to keep the metadata within your model project or with the domainservice. For me, metadata is still a part of model, as it only describe the entities attributes more, so I tend to copy metadata files to a special metadata folder within the model project.

Read more…

The ADO.NET Entity Framework Overview (MSDN)
ADO.NET Entity Framework (MSDN)
Programming Entity Framework 4 (book)

Comments are closed.