Posts Tagged ‘Starter Wizard’

Introducing CodeFluent Entities MySQL Producer

August 16, 2012 Leave a comment

CodeFluent Entities 2012 – Build 060703 introduced a new Persistence layer producer: the MySQL Producer! The producer supports MySQL 5.1 and above and relies on the MySQL Connector for .NET version The producer will try to load dynamically the MySql.Data assembly. You might need to copy the MySql.Data.dll in your CodeFluent Entities installation directory if you don’t want to register the MySQL Connector in the GAC.

Getting started

The producer is available in the Persistence Layer Producers section of the Add New Producer window:

as well as directly from the Starter Wizard:

This is how you can set the connection string (in the Wizard pages):

A first model

I created a new project with the Start Wizard and designed this very simple model composed of two entities:

Basically all the employees have a first name, a last name, a birth date, and a job. Each job has salary – of type currency, a name and employees.

I added two instances to the model: an employee named John Doe, born on June 12th, 1974 with a job named CEO and which salary is 30,000.

I also set the Target Version property of the MySQL Producer to version 5.5, which is the version I am currently using on my computer, and built the project, like any other CodeFluent Entites project. In the output window I can see the result of the generation process. The MySQL producer has generated 9 files and succeeded:

All the automatically generated .SQL script files are available in the Persistence project of the solution:

If I connect to my MySQL database with an administration tool I can see that a new database has been created with the named I specified in the Connection String, and populated with the tables automatically inferred from my model as well as instances:




And I haven’t written a line of code yet!

Consuming the generated persistence layer

Consuming the MySQL generated database is as easy as configuring the right connection string in the client project. I my case, I created a Console Application Project named MyCompany.Management.Client.

To prepare it, I had to reference my BOM Project – in my case MyCompany.Management – that was automatically created by the Starter Wizard, MySql.Data.dll (the MySQL ADO.NET provider) and the CodeFluent Entities runtime, i.e. CodeFluent.Runtime.dll and CodeFluent.Runtime.MySQL.dll. Note that you might need to set the Copy Local property to True for the MySql.Data.dll reference if the dll is not registered in the GAC.

I also had to change the target framework of the project from .NET Framework 4.0 Client Profile to the full .NET Framework 4.0.

As I am using the MySQL Producer I have to set the correct Connection String in App.config file:

<?xml version="1.0"?>
    <section name="MyCompany.Management" type="CodeFluent.Runtime.CodeFluentConfigurationSectionHandler, CodeFluent.Runtime" />
  <MyCompany.Management persistenceTypeName="MySQL" connectionString="Server=localhost;Database=MyCompany_Management;User Id=root;" />

Note that it is important to specify the persistenceTypeName=“MySQL” attribute, otherwise we would be using the default persistence layer which is SQL Server. Here is the code of my console application :

using System;
namespace MyCompany.Management.Client
  class Program
    static void Main(string[] args)
      // Create a new employee
      Employee newbie = new Employee();
      newbie.FirstName = "Jane";
      newbie.LastName = "Doe";
      newbie.BirthDate = new DateTime(1990, 01, 15);

      // Persist Jane Doe

      // Load all the employees
      EmployeeCollection employees = EmployeeCollection.LoadAll();
      foreach (Employee employee in employees)
        Console.Write("- {0} {1}, born on {2:MM-dd-yyyy}",

        if (employee.Job != null)
          Console.Write(", is {0} with a salary of {1:C}",


It creates a new employee, saves it, and then loads a list of all the employees. As we can see, there is no specific code about MySQL. Its use is completely transparent at this level.

And here is the result:

And the populated table:


Happy MySQL-ing!

Baudouin Giard

Adding your own models to the CodeFluent Entities Starter Wizard

December 29, 2011 Leave a comment

As mentioned in the posts “The Starter Wizard” and “New CodeFluent Entities Milestone”, the Modeler provides a wizard creating the structure of your solution as well as configuring your producers so they point to the freshly created projects.

Among the wizard pages, there’s a page allowing you to select a model template from which you want to start:

Models displayed in this page are the default official ones (blank, and sample ones), but just as you can add your custom producers or custom rules to the Modeler, you can add your custom models to his screen as well.

First you need to locate the custom configuration. You’ll find this information by:

  • opening Visual Studio,
  • go to “Tools > Options… > CodeFluent Entities”,
  • and select the advanced view using the advanced button at the top of the property grid.

As you’ll see, there’s a property named “Custom Configuration File Path” which points to a Custom.config file:

Open this file (or create it if necessary) and add the following XML content to it:

    <starterWizardModelDescriptor name="Test" fileName="Test.cfxproj" description=”A custom model.” />

This indicates the Starter Wizard to display a model named “Test”, corresponding to the “Test.cfxproj” project, in the “Select your model” wizard page.

Note: the cfxproj file should be placed in CodeFluent Entities’ Visual Studio templates folder which is “C:\Program Files (x86)\SoftFluent\CodeFluent\VSTemplates\Projects”).

Save the file, open your wizard, here’s what you should see now:

And voilà: our custom model project is now proposed in the wizard!