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.
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!
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)
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!
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.
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.
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" >
<WeekDays value="Monday,Tuesday,Wednesday,Thursday,Friday" />
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 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
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.
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!