[This is preliminary documentation and subject to change]
![]() |
Note: Even though this tutorial was realized using Microsoft Visual Studio 2010, it also applies to Microsoft Visual Studio 2008. |
Preparing your development environment
First of all we'll prepare our development environment.
The first step is to open Microsoft Visual Studio, and create a new project. We'll name the project Sample and the solution will have the same name.
The project type is a Class Library and this Sample project will contain the business model of our application.
Secondly, we're going to create two other projects:
• A SQL Server 2008 Database Project (or SQL Server 2005 Database Project, depending on your configuration) named Sample.Persistence which will contain the generated scripts used to create the persistence layer,
• A Blank CodeFluent Entities Model (located in the “CodeFluent Entities” template category) named Sample.Model which will contain our CodeFluent Entities model and its related resources.
A default namespace dialog will pop-up, ensure the default namespace of your application is Sample.
Suppress the Class1.cs files that Visual Studio automatically creates for Class Library projects.
In the end, your solution should look as so:
Now that our Microsoft Visual Studio projects correspond to the CodeFluent Entities-generated application blocks; we're going to model our application in the Sample.Model project and configure CodeFluent Entities to generate the source code in the Sample.Persistence and Sample projects.
Modelling the business concepts
We are going to model a ridiculously simple application which can handle only three concepts: a customer that can order products.
This is done intentionally: the tutorial's purpose is to demonstrate how to set up a n-tier architecture with a custom web site as a front office. We won't demonstrate modelling principles in this tutorial.
Opening the Surface
Go to the Sample.Model project -> Surfaces:
Double-click on Default, to open the surface.
This will open the Default surface. It is empty because we don’t have entities on this Surface yet.
![]() |
[This is preliminary documentation and subject to change] Note: In beta version, good practice is to save frequently in order to avoid any bad surprises. |
Adding entities
Now, Right-Click in the Default surface -> Add -> Entity.
A window will pop up. Name the entity Customer and add it to the Sample namespace.
Repeat those steps for the Order and Product entities (add entities to the existing Sample namespace).
Your model should look like this :
Adding properties to entities
Our entities were added to the model, we now can add their properties.
Right Click on the Customer entity -> Add -> Property
In the dialog, name the property Id and set its type as an int.
![]() |
Note: Instead of typing the type name yourself, you can also select it from a predefined list. |
Add the following Standard Properties:
Customer:
- Id (int)
- Name (string)
- Address (string)
Order:
- Id (int)
- Code (string)
- Date (datetime)
Product:
- Id (int)
- Code (string)
- Label (string)
- Price (currency)
You can also add Advanced Type properties. Just add a new property to Customer, name it Orders, and in Type choose Advanced and browse for the desired type.
A new dialog will appear.
Select the Order type (Sample).
Add the following relation properties:
- On the Customer entity, add a Orders property (leave the type at string),
- On the Order entity, add a Customer property (leave the type at string),
- On the Customer property of the Order entity, hold SHIFT+Click on the property, an arrow appears, and make the arrow point to the Orders property of the Customer entity.
- A dialog will pop-up so you can specify the multiplicity of your relation,
- Define it as one Customer has many Orders.
[TODO: Screenshot]
- On the Order entity, add a Products property (leave the type at string),
- SHIFT+Click on the Products property and make it point to the Product entity,
- In the multiplicity dialog, set the multiplicity to Many-To-Many and set the target property to unspecified.
Here is the final model:
Now that our business logic is modeled, we're going to add producers.
Generating
Before generating, we need to configure our producers.
We want to generate the persistence and the business layers, so we simply have to add two producers: one for the persistence, and one for the BOM (Business Object Model).
To add a producer, Right Click on the default surface and select Add -> Producer
The “Add new producer” window will appear. We will first add a persistence producer which in our case will be SQL Server. To do so select “SQL Server” under “Persistence Producers”.
To add it, we need to specify where the producer will put the generated files. Browse the Target Directory (under Production) to open the “Browse For Project Folder” dialog. Select the Sample.Persistence project and click OK.
You may also need to specify the connection string of your SQL Server instance. Otherwise, it will use the default one (Application Name=[DefaultNamespace];server=127.0.0.1;database=[DefaultNamespace];Integrated Security=true).
To set the connection string, browse Connection String (under Production) and fill the popup with the desired information.
Example:
![]() |
Note: Since the database wasn't generated yet, you don't have to specify a database name. |
Confirm all your changes, and you will see a new area which appeared on the surface, next to your entities. This area will contain all your producers.
Repeat the previous steps to add a Business Object Model Producer which will be used to generate files in the Sample class library project. Do not forget to set the Output Name to “{0}.dll”
Once added, your default surface should look like this:
Building the Sample.Model project will generate the files. Build it and wait for the completion.
Upon completion, you will see files and references added to your solution.
Congratulations, you have generated your first solution using CodeFluent Entities!
At this point, we generated the persistence layer (database, tables, stored procedures, constraints, etc.), and a set of CSharp classes allowing us to manipulate those persistence objects in upper layers (e.g. in the UI). We now have the foundations of all business applications: whether they are an ASP.NET Web Site, a rich client or a smart client, they will be built on top of those two layers.


