Archive
What’s CodeFluent Query Language?
CodeFluent Query Language (a.k.a. CFQL) allows you to write platform independent data accessing queries which producers (producer = code generator) will translate into optimized stored procedures.
For instance you can define the following CFQL query in your model:
<cf:method name="LoadByName" body="load(Name) where Name startswith @Name"/>
The SQL Server Producer will generate the following stored procedure:
CREATE PROCEDURE [dbo].[Test_LoadByName]
(
@Name [nvarchar] (256)
)
AS
SET NOCOUNT ON
SELECT DISTINCT [Test].[Test_Id], [Test].[Test_Name]
FROM [Test]
WHERE ([Test].[Test_Name] LIKE (@Name + '%'))
RETURN
And the Oracle Database Producer will generate the following equivalent:
PROCEDURE LoadByName(CF_CURSOR OUT "Sample"."CF_#Runtime".CF_CURSOR_TYPE,
"#Name" NVARCHAR2) AS
V_CF_CURSOR "Sample"."CF_#Runtime".CF_CURSOR_TYPE;
BEGIN
OPEN V_CF_CURSOR FOR
SELECT "Test"."Test_Id", "Test"."Test_Name"
FROM "Sample"."Test"
WHERE ("Test"."Test_Name" LIKE ("#Name" || N'%'));
CF_CURSOR := V_CF_CURSOR;
END;
As you can see data accessing queries are not built in-memory dynamically at run time but instead a classic stored procedure is generated at development time.
As a consequence developers can:
- see what’s going to happen at run time and avoid bad surprises (like this one when using EF for instance),
- debug it easily if they need to,
- change the code if the need to.
Cheers,
Carl Anderson
SoftFluent Team at DevWeek London!
DevWeek 2012 kicked-off this morning with great workshops and as announced previously: we’re there!
Starting tomorrow, come have a chat with us at our booth!
Cheers,
Carl Anderson
CodeFluent Entities: Initializing your application with data
In our previous posts, we’ve seen that from a single platform independent model (see CodeFluent Entities is not an ORM) you can generate continuously (see Continuous Generation) complete databases, .NET classes, web services or UIs.
That’s great but when you’re developing your application, this will all be empty and just like an empty party, an empty app is no fun ![]()
Well using CodeFluent Entities, from Visual Studio, you can specify “instances of data” in your model. What’s great about instances is that persistence producers such as the SQL Server producer, Oracle Database producer or SQL Azure producer, will translate those into a SQL script which will insert/update data in your app!
Here’s an example:
Select an entity and click on “Add Instance” to add instances one by one using the instance dialog.

You can also use the instance grid (accessible from the ribbon, in the “Batch Modeling” group) to multiple instances at a time in a grid:

For the newcomers, we published a while ago a 1 minute video illustrating how to generate code and data using CodeFluent Entities, plus using the generated code right away in the following post: How to generate with data (video)
Cheers,
Carl Anderson
CodeFluent Entities: Continuous Generation
In the previous post, CodeFluent Entities is not an ORM, I briefly talked on how CodeFluent Entities is different from an ORM as your not mapping a database to an object model but instead your defining a model from which you’ll generate stuff depending on the code generators (a.k.a. “producers”) you specified in your project.
Therefore CodeFluent Entities is a very DRY product as from a single model you’ll update consistently your database, classes, services, UIs, and so on. However, as we developers know, there’s absolutely no way you’re going to model your entire application the right way on the first shot: specs move along, we always forget something or just did not think of a particular scenario…
As a consequence such a product would be useless without continuous generation. By continuous generation I mean that you can go back to the model do some changes in it and generate over to update consistently all your layers without losing changes nor data!
Example:
Everything starts from the database where CodeFluent Entities’ differential engine enables hassle-free schema updates without losing any data.
Say you have an existing Customer entity:

From which you generated a Customer table containing data:

Adding a new Name property to the entity:

And generating over will preserve our existing data:
Last but not least, please note that things like up-casting, adding/removing constraints or relations are fully supported so you can generate continuously throughout your developments.
Cheers,
Carl Anderson
CodeFluent Entities is not an ORM
CodeFluent Entities is a unique product integrated into Visual Studio 2008/2010/vNext which allows you 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.
For instance, adding an instance of the SQL Server Producer to your project will translate your model into a database (schemas, tables, stored procedures, views, constraints, etc.):
Adding an instance of the Business Object Model Producer will translate your model into .NET classes (C# or VB.NET) consuming the persistence layer:
Adding a WCF Producer will generate WCF services, contracts and proxies exposing your .NET classes:
Adding a WPF Smart Client Producer will generate a WPF application consuming the WCF services thanks to the generated proxy:
And that’s just an example of what you can do: you can also build ASP.NET web sites, SharePoint apps, Windows Forms apps, Silverlight apps, etc.
Your application is layered following best practices, all its business logic is in the middle-tier (the Business Object Model generated by the Business Object Model producer), and supporting a new technology gets down to adding a new producer or creating screens on the generated code.
Last but not least, you can create your own producer which translates this inferred meta-model into what you need.
Cheers,
Carl Anderson
New CodeFluent Entities Version Released!
A new CodeFluent Entities version (646) has been released and is publicly available!
You can download it from here: CodeFluent Entities Download Page.
Enhanced Visual Studio 11 Beta integration
Remember the “CodeFluent Entities & Visual Studio 11 Beta” post? Well we kept our word and corrected the glitches ![]()
SQL Server 2012 is supported by the SQL Server Producer
More details in this post: Added SQL Server 2012 Support
Enumeration declarations now support named values
You can now do stuff with multi-valued enumerations such as (supported separators are , ; | and +):
<cf:enumeration name="WeekDays" multivalue="true" >
<None />
<Sunday />
<Monday />
<Tuesday />
<Wednesday />
<Thursday />
<Friday />
<Saturday />
<WeekDays value="Monday,Tuesday,Wednesday,Thursday,Friday" />
</cf:enumeration>
(Thank you GregD for the suggestion)
Project Level “Implements” and “Set Implements” rules
You can define “Implements” and “Set Implements” rules at project level so all generated classes implement a specific interface or derive from a specific class (http://forums.softfluent.com/default.aspx?g=posts&t=395).
Transaction rules
Transaction rules can now be added on methods other than Save and Delete, including custom ones. Developers don’t have to write the TransactionScope code themselves when adding a new custom method: all it takes is selecting your method and add a transaction rule on it ![]()
The Modeler now supports Aspect assemblies
If you are familiar with CodeFluent Aspects, you already know that you can develop aspects in XML or in .NET assemblies.
You’ll be glad to know that the Modeler now fully supports .NET assemblies including assemblies containing multiple aspects (e.g. Contoso.Aspects.dll). In such cases it displays available aspects in the assembly and lets you select the one you want to use in your current CodeFluent Entities project.
Miscellaneous changes
Some other miscellaneous things were also added/fixed/enhanced such as the enhancing TFS integration or adding support for the CTRL+A keyboard shortcut in the method body editor was added.
We would love to hear your feedbacks, don’t hesitate to share your feedbacks on our forums or by commenting this post!
Enjoy,
Carl Anderson
CodeFluent Entities: Added SQL Server 2012 support!
Microsoft recently released to manufacturers its latest version of Microsoft SQL Server (Microsoft SQL Server 2012) and good news for our users: CodeFluent Entities supports SQL Server 2012!
No changes to your projects are needed:
- just generate over again your persistence layer (this time pointing on your brand new SQL Server 2012 server!),
- update your application so it uses the new persistence layer,
- Taaadaaaa, you’ve just migrated your app to SQL Server 2012, cool right?!!
Note: Did you know SQL Server Management Studio 2012 is now in a Visual Studio 2010 Shell?!!
Prerequisites to do this are as usual:
- CodeFluent Entities (build 60314.646 or upper)
- If SQL-DMO wasn’t installed on the server, you can download it from here (only the “Microsoft SQL Server 2005 Backward Compatibility Components” is needed): http://www.microsoft.com/downloads/en/details.aspx?FamilyId=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C&displaylang=en
Cheers,
Carl Anderson
Dates and JSON
JSON (JavaScript Object Notation) is a lightweight text-based open standard designed for human-readable data interchange (source: Wikipedia).
JSON is so very handy but one thing I hate about JSON is that its spec is so lightweight that it sometimes lacks some details on specific areas such as for dates. Scott Hanselman’s post “On the nightmare that is JSON Dates. Plus, JSON.NET and ASP.NET Web API”, is actually a perfect example of the kind of troubles you run into when building web sites and using various JSON serializers.
We bumped into this as we’re working on the next version of our ASP.NET Web Producer which will ship with an Ajax web site template (JQuery + JqGrid + JSON/REST) allowing developers to generate business oriented web apps (see our roadmap post for more info on this subject).
Anyway, when developing a business web site we, developers, have to support dates and since their format can vary in JSON, our JSON serializer/deserializer class (named JsonUtilities) supports several:
- \/Date(1330848000000-0800)\/, with or without “TZ“ by the way (this is our default, read this to know why: http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx)
- new Date(utc milliseconds)
- ISO 8601
So if ever you need to support several date formats without having to switch JSON serializers/deserializers for each scenario, keep this JsonUtilities class in a corner as I’m sure it’ll come handy.
By the way, this JsonUtilities class is shipped as part of a free NuGet package, independently from our product, named CodeFluentRuntimeClient.
Here’s it’s web page if you want to try it out (http://nuget.org/packages/CodeFluentRuntimeClient) and here’s a post containing some serialization examples (JsonUtilities – Part 2) ![]()
Cheers,
Carl Anderson








