Archive for July, 2012

CodeFluent Entities: Writing a custom aspect

July 27, 2012 1 comment

In the previous post, we’ve seen that CodeFluent Entities infers a meta-model from our model and that we could interact with this meta-model to apply application wide changes. In this post we’ll see how Smile

Step 1: Writing your aspect

As an example we’ll write an aspect which will add a “IsDeleted” property on all entities by default.

First of all, we added a new class library project named “Demo.Aspects” to our solution and added the following references: CodeFluent.Model.dll,  CodeFluent.Model.Common.dll and CodeFluent.Runtime.dll. Aspects can either be written in XML or in .NET. In my opinion, it’s easier to start writing aspects in .NET as you’ll have Visual Studio’s IntelliSense which will help you out using the API.

In practice, an aspect is a class implementing the IProjectTemplate interface. This interface contains a single method “Run” which takes as a parameter a “context”.

Here’s a sample implementation:

using System.Collections;
using System.Xml;
using CodeFluent.Model;

namespace Demo.Aspects
    public class MyAspect: IProjectTemplate
        public static readonly XmlDocument Descriptor;
        public const string MyAspectNamespace = "";

        static MyAspect()
            Descriptor = new XmlDocument();
@"<cf:project xmlns:cf='' defaultNamespace='MyAspect'>
    <cf:pattern name='My Aspect' namespaceUri='" + MyAspectNamespace + @"' preferredPrefix='mya' step='Tables'>
        <cf:message class='_doc'>This is some description for our custom aspect.</cf:message>
        <cf:descriptor name='enable'
            category='My Custom Aspect'
            displayName='Add the MyCustomProperty'
            description='Description for our custom descriptor.' />

        public XmlDocument Run(IDictionary context)
            if (context == null || !context.Contains("Project"))
                // we are probably called for meta data inspection
                return Descriptor;

            // the dictionary contains at least these two entries
            XmlElement element = (XmlElement)context["Element"];
            Project project = (Project)context["Project"];

            foreach (Entity entity in project.Entities)
                Property property = new Property();
                property.Name = "IsDeleted";
                property.TypeName = "bool";

            // we have no specific Xml to send back, but aspect description
            return Descriptor;

The method returns a XmlDocument which is described above as a string. It could also be written on a separate file.

As you can see this XML defines the aspect’s name, its XML namespace, and how it extends the CodeFluent schema (here it adds a “mya:enable” attribute on entities, whose default value is false).

Step 2: Using your aspect

Compile the “Demo.Aspects” project.

In the solution explorer, select the “Aspects” folder and click “Add Existing Aspect…”. Browse for our Demo.Aspects.dll that we created previously and here’s what you should see:


Great! As you can see, information returned by our descriptor is properly parsed and displayed Smile

Hit OK, and now by default all your entities should have an extra “IsDeleted” property added when the model is inferred, which means that a “IsDeleted” column will be created for all tables, all stored procedures will be updated to include this column, and it’s the same in the middle tier and the UI tier. You can view this by clicking on the “View Inferred Model” button available in the ribbon:


Useful Links

Hope this helps,

Carl Anderson

CodeFluent Entities: Basics, meta-model and aspects

July 26, 2012 Leave a comment

CodeFluent Entities is a product integrated into Visual Studio 2008/2010/2012 which allows developers to generate components such as scripts (e.g. T-SQL, PL/SQL), code (e.g. C#, VB), web services(e.g. WCF, ASMX) and UIs (e.g. ASP.NET, SharePoint, WPF).

The code generation process is model-first and continuous: from your declarative model, a meta-model will be inferred which code generators will then translate into code. Over 20 code generators (a.k.a. “producers”) are provided “out of the box” and can be combined to create your own application following your desired architecture, using your desired technologies.


figure 1 

Figure 1 is in fact a little too simple: as mentioned earlier, producers don’t translate your model into code right away, instead a meta-model will be inferred first. This meta-model consists of of a ‘virtual’ persistence layer, a ‘virtual’ business object model and a ‘virtual’ user interface. By ‘virtual’ I mean that it’s all in-memory and that’s not actual code yet.


figure 2

You can actually view those virtual bits using the Meta-Model Explorer (CodeFluent.View.exe) or by clicking on the “View Inferred Model” button of your project tab in Visual Studio:


figure 3

Producers will then translate those virtual bits into actual scripts, code, web services and UIs.

This meta-model is the key. Thanks to it, before anything gets generated, CodeFluent Entities can ensure that your application is consistent and that it will all compile.

Furthermore, CodeFluent Entities provides what we call “CodeFluent Aspects” (formerly known as “CodeFluent Patterns”) which allow you to interact with this inferred meta-model and dynamically change it.

A set of built-in aspects are provided out-of-the-box but you can also create your own aspects. For instance, one could create an aspect that automatically adds tracking properties on all entities marked as “trackable”. It’s all done at generation time and can turn out to be very handy when working on big models and/or to externalize a feature that you have to implement often from one project to another.

More on this subject in a forthcoming post!



Carl Anderson

CodeFluent Entities: new ASP.NET Web Site Web Forms Template sneak peek

July 25, 2012 2 comments

A brand new ASP.NET Web Site Producer (v2) is shipped in alpha in the latest build available (666 and upper).

As mentioned in our Web Platform Roadmap post, this new producer will be shipped with three templates:

Here’s a sneak peek of what gets generated when using this new template (codename: “Airport”) Smile

The homepage generated by default lists all namespaces and their contained entities:



Clicking on an entity gets you to the entity page:


On this entity page you’ll find a screenshot of the entity from which this page was generated.

On the left side of the page you’ll find a list of actions available on this entity. Those actions correspond in fact to business methods provided by the entity:



Unlike the Ajax/JSON template which consumes WCF JSON services, the ASP.NET Web Forms template is built directly on top of your generated .NET Domain Model, skipping this service layer. Yet, the generated .NET Domain Model (a.k.a. .NET Business Object Model) is not specific to ASP.NET and the exact same object model can be used from any other .NET technology such as SharePoint, WinForms, Console applications, services, etc.


Any feedback? Share them on this blog, on our forums or on our Facebook page!


Carl Anderson

July 24th 2012 Links: Software development, Windows Azure, Office

July 24, 2012 Leave a comment

Here’s our new entry in our link-listing series:


Software Development

Is the laptop doomed?

Ahaha, we’re not quite there yet, but we sure are getting there Winking smile


Entity Framework now Open Source

Big news: The Entity Framework source code is today being released under an open source license (Apache 2.0), and the code repository is now hosted on CodePlex (using Git).



MonoGame is an Open Source implementation of the Microsoft XNA 4 Framework. Its goal is to allow XNA developers on Xbox 360, Windows & Windows Phone to port their games to the iOS, Android, Mac OS X, Linux and Windows 8 Metro.  (PlayStation Mobile development is currently in progress.)


Windows Azure

SOSP Paper – Windows Azure Storage: A Highly Available Cloud Storage Service with Strong Consistency

Wow, that’s interesting: the paper describes how Microsoft provisions and scales out capacity within and across data centers via storage stamps, and how the storage location service is used to manage their stamps and storage accounts. Then it focuses on the details for the three different layers of the architecture within a stamp, why these layers, what their functionality is, how they work, and the two replication engines.

A must read!



Microsoft’s new Office: The cloud finally takes center stage

A sneak peek of Office 2013 (a.k.a. Office 15)


Microsoft released new Office (Customer Preview)

The new Office is available online (preview).


Introducing “Napa” – Office 365 Development Tools

The Visual Studio team released a preview of a new toolset called “Napa”, which is, as they say, “the easiest way to start building apps for the new Cloud App Model”.


Hope this helps,

Carl Anderson

Setting-up Oracle Database for .NET development

July 13, 2012 Leave a comment

I recently had to set-up a new development environment for a .NET application consuming an Oracle Database and found out that it wasn’t that easy, so I thought I’d share how I did it.



I’m just sharing my config and the way I did it.

SoftFluent cannot be held responsible if something goes wrong or does not work, and no support is provided. It’s neither official documentation nor the only way to do it, I’m just sharing my recipe Smile



I downloaded and installed a free Oracle Database Express Edition.

The 11g Release 2 is available here:

Yet, in this case I had to install a 10g in 32-bit which can’t be found on OTN anymore…..except on a Japanese OTN page?!!

If you need the Oracle Database 10g Express Edition (x86) as I did here’s the link:


Installing the Server

Nothing special here: install OracleXE.exe, keep everything by default:

  • installation directory: C:\oraclexe
  • default port: 1521
  • configure the SYS or SYSTEM account

Once installed, an administration web page should start. Check that everything runs fine, if so, you’re done, now let’s prepare it for the .NET world!


Installing OCI & ODP.NET

Oracle Call Interface (OCI) is the basic and compulsory method to access Oracle using a client. On top of OCI, we’ll need the Oracle Data Access Components (ODAC). Both OCI and ODAC are a set of dlls and that are shipped as a ZIP, available on Oracle’s web site (

In my case I specifically needed the, in your case just be careful to use an ODAC version matching your Oracle Database version and bitness.

Then here’s how I configured my environment:

  • I created a “C:\oracle” just like OracleXE did,
  • I extracted the content of my archive in this directory,
  • I removed the path C:\oraclexe\app\oracle\product\10.2.0\server\bin” from my PATH environment variable…
  • …and added the “C:\oracle\instantclient_11_1” in the PATH so my OCI dlls are used,
  • I copied the Oracle.DataAccess.dll that is in “C:\oracle\odp.net20\\bin\2.x\” in “C:\oracle\instantclient_11_1”,
  • I removed all Oracle.DataAccess.dll from the GAC so I’ll be sure my .NET apps we’ll always use the Oracle.DataAccess.dll they reference,
  • I copied the OraOps11w.dll contained in the “C:\oracle\bin” in “C:\oracle\instantclient_11_1”


Installing SQL Developer



Setting-up CodeFluent Entities

Since we removed Oracle.DataAccess.dll from the GAC, we need to place it in CodeFluent Entities directory so the Oracle Database Producer can access it.


Hope this helps,

Carl Anderson

CodeFluent Entities: How to reuse existing stored procedures

July 13, 2012 Leave a comment

In this post I’ll start from the NerdDinner application, which you can get from CodePlex ( In the NerdDinner database I added the following sample stored procedure named “sp_SelectDinnersByCountry” that takes a county name as a parameter:

CREATE PROCEDURE [dbo].[sp_SelectDinnersByCountry] 
     @Country [nvarchar] (50)
    FROM Dinners 
    WHERE Country = @Country

From there, I then imported the NerdDinner database into a brand new CodeFluent Entities model (as detailed on CodeFluent Entities’ Get Started page) and now what I want to do is to reuse my existing stored procedure, instead of creating a new one using CFQL.

Select the “Dinner” entity and add the following new method:


Now that our method is created we need to specify:

  • it’s name in the persistence layer as my stored procedure has a different name than the one in my model,



  • it’s return type (by default raw methods are void),



  • mark my method so it’s not generated by the SQL Server Producer,



As a consequence the Business Object Model Producer will generate a SelectByCountry method, which calls the sp_SelectDinnersByCountry stored procedure, and returns a DataSet, so now in my app I can do something like this:

System.Data.DataSet ds = Dinner.SelectByCountry("FRANCE");


Hope this helps,


New CodeFluent Entities Menu in Visual Studio

July 12, 2012 Leave a comment

Since a few builds now, installing CodeFluent Entities adds a new menu in the Visual Studio toolbar:



This menu contains a set of shortcuts to get started quickly using CodeFluent Entities:

  • New Project…: equivalent to “File > New > Project…”
  • Import an Existing Database or Model…: launches a new wizard which is a combination of the starter wizard (to create and configure your solution) and the import wizard (to create a model from an existing line of business).

A detailed tutorial is available here: Get started from an existing database or model

  • Starter Wizard…: launches a wizard to help you create a brand new CodeFluent Entities solution.

A detailed tutorial is available here: Get started using the Starter Wizard

  • Getting Started: opens the Get Started page in a browser,
  • CodeFluent Entities Blog: opens this blog Winking smile
  • Online Documentation: opens the product documentation,
  • Submit Feedback: opens a feedback form you can use to send us your comments,
  • Product Updates: a link to the CodeFluent Entities RSS Feature Feed. You can subscribe to this RSS Feed to be automatically notified of new features and bug fixes in the product,
  • Request a FREE License: opens a form letting you retrieve a free personal license from Visual Studio,
  • About CodeFluent Entities…:



Carl Anderson