Archive for April, 2011

Comments in Models

April 29, 2011 Leave a comment

Using the Core Edition only, and consequently writing your model in plain XML, developers could embed XML comments in it explaining what they meant to do, or using them as reminders of what’s left to do.

In latest Modeler builds, you might have noticed that we introduced the an “Add Note” button in the modeler pad tab of the ribbon:


Well clicking this button allows you to place notes on the surface:


This way fans of XML comments in the Core Edition won’t be prejudiced!

Table-Valued Parameters

April 28, 2011 Leave a comment

Microsoft, starting with SQL Server 2008, added support for a new parameter type in SQL Server: Table-Valued parameters. Using them, you can send multiple rows of data to a T-SQL stored procedure, without creating a temporary table for instance.

Starting with the build 50204.579, the SQL Server producer now provides built-in support for those types. Thanks to this new feature you can now design CFQL queries such as:

<cf:method name="LoadCategories" body="load(int[] ints) where Id in (@ints)"/>

Which will generate the following code:

CREATE TYPE [dbo].[cf_type_Category_LoadCategories_0] AS TABLE(
[Item] [INT] NULL)
CREATE PROCEDURE [dbo].[Category_LoadCategories]
@ints [dbo].[cf_type_Category_LoadCategories_0] READONLY,
@_orderBy0 [nvarchar] (64) = NULL,
@_orderByDirection0 [BIT] = 0
DECLARE @_c_ints INT; SELECT @_c_ints= COUNT(*) FROM @ints
SELECT DISTINCT [Category].[Category_Id], [Category].[Category_Name], [Category].[_rowVersion]
FROM [Category]
WHERE [Category].[Category_Id] IN ((SELECT * FROM @ints))

The feature is actually broader than that, you can also:

  • In CFQL, use the ‘=’ operator on table-valued types, e.g. count(int[] ints) where @ints = Id,
  • Use .NET CLR types, e.g. raw(System.Uri[] uris),
  • Use already existing table-valued types in database,
  • Map table-valued types to .NET types such as DataTable, IDataReader and IEnumerable<SqlDataRecord>,
  • Map them to generated collection types you created in the model.

Want to know more about it? It’s all detailed in our product documentation, in the Array Parameters article.

Categories: SQL Server Tags: ,

Introduction to the SharePoint Producer

April 27, 2011 2 comments

The Microsoft SharePoint Producer is a user interface producer as its main purpose is to generate generic entity SharePoint Web Parts that can be used configured and deployed in SharePoint Web Part pages. All Web Parts are designed to be related to any entity from the Business Object Model (BOM).

The producer generates four kinds of Web Parts:


The EntityDataSourcePart, unlike the three other Web Parts, doesn’t have a user interface. It’s an invisible Web Part (similar to the ObjectDataSource control in ASP.NET) designed to act as a data source for both EntityFormPart or EntityGridPart. If the EntityDataSourcePart is used as a data source to the EntityFormPart, the entity selected in the EntityDataSourcePart will be shown in the EntityFormPart. The same logic is true when used as an EntityGridPart data source. Furthermore, it can call parameterized methods. In such cases, parameters must be configured so they can be passed to the underlaying method. The EntityDataSourcePart can also use the query string in order to retrieve parameters and forward them to the underlaying method.



The EntityMethodPart provides an interface so end-users can supply parameter values of a given method. It’s interface is a form composed of input fields. Typed-in values will be parsed and made available to connected Web Parts.

The EntityMethodPart is a “supplier-only" Web Part and is designed to supply values to a connected EntityGridPart; it doesn’t display data itself.



The EntityGridPart is a Web Part intended to display within a grid control, records of business entity instances. The EntityGridPart can “consume” parameters provided by an EntityMethodPart in order to load the collection to be displayed. It can also supply a selected entity instance to a connected EntityFormPart.



The EntityFormPart is a form Web Part which displays the properties of a selected instance of business entity. Using this part, not only end-users can get a detailed view of an instance, but they can also update or delete the current instance. The EntityFormPart is a “consumer-only” Web Part. Consequently, it needs a data source from which to consume data. The data provider may be a connected EntityGridPart as well as an EntityDataSourcePart. Finally, it’s also possible to configure the EntityFormPart to use the query string as input.

The following screenshot actually shows different Web Parts, configured to manipulate an Account entity, and connected to one-another:



Going from top to bottom, the first Web Part is an EntityMethodPart configured to use the LoadByName method of the Account entity. Moreover, this Web Part was configured to supply typed-in values to the second Web Part: an EntityGridPart.

The second Web Part is an EntityGridPart which is mapped to the same LoadByName method, and uses the parameter values provided by the first Web Part (EntityMethodPart) when invoking the method. Data returned by the method are then displayed in the grid.

The third and last Web Part is an EntityFormPart configured to show in a form, the currently selected instance in the EntityGridPart.

All those web parts are generated, and more than just generating web parts as we’ve seen in this post, CodeFluent Entities provides an extensive set of features made to ease the developer’s task when it comes to developing SharePoint applications, such as:

  • Site Creator,
  • Binary Large Object Management,
  • Office Synchronizable Lists Integration,
  • Runtime Model,
  • and more (localization, authorization, validation, etc.).

Check-out our documentation for more information!

Generating Documentation

April 26, 2011 Leave a comment

CodeFluent Entities provides a documentation sub-producer which allows you to:

  • Decorate all members with XML comments (usable by Visual Studio IntelliSense and help tools),
  • Generate XML, batch and configuration files to create a .CHM documentation using Sandcastle.

To benefit from it, you first need to add an instance of the sub-producer. To do so, select the Business Object Model Producer instance of your project, right-click on it and select “Add New SubProducer”. Then in the “Add New SubProducer” dialog, select “Documentation” in the tree view and configure it:


Note: the only required property is the “Sandcastle Target Directory “which needs to be specified so the producer knows where to generate its output files. If producing Sandcastle files, you need to have Sandcastle installed before generating and ensure the Sandcastle path is correct so you’ll be able to use the generated files right away.

Since decorating all members of all your generated classes all the time can be quite an overkill during developments, it is disabled by default in the Business Object Model producer, so you need to enable it as well. Double-click on your Business Object Model producer instance to open its configuration and set “Generate Xml Documentation” to “True”:


In the XML this looks like something like that:

<cf:producer typeName="CodeFluent.Producers.CodeDom.CodeDomProducer, CodeFluent.Producers.CodeDom">
  <cf:configuration targetDirectory="..\Sample" outputName="{0}.dll" generateDocumentation="true">
    <subProducer typeName="CodeFluent.Producers.Documentation.DocumentationProducer, CodeFluent.Producers.Documentation"
                 targetDirectory="..\Doc" sourceDirectory="%CF_TEMPLATES_PATH%\Documentation" />

Build over your project and you’ll see that all your members have XML remarks on them! Moreover, in the Sandcastle Target Directory you specified, you’ll see a set of files allowing you to generate a .CHM file documenting the generated objet model Smile

Razor Syntax Support

April 12, 2011 Leave a comment

We introduced the Text Template Engine in previous posts such as this one, or this one; and both posts feature some quick examples of how to use the default syntax to create templates:

  • use [%= foo %] to print the value of the foo variable,
  • use [% foreach (string value in values) %] to embed C# statements.

Starting with the next CodeFluent Entities build (> 50401.587), the CodeFluent Template Engine now supports Razor.

Razor, is basically a new view engine for ASP.NET MVC developed by Microsoft and shipped with ASP.NET MVC 3. Basically, the main goal of Razor is that it’s compact, expressive and fluid. To quote Scott Guthrie (view source):

Razor minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow. Unlike most template syntaxes, you do not need to interrupt your coding to explicitly denote server blocks within your HTML. The parser is smart enough to infer this from your code. This enables a really compact and expressive syntax which is clean, fast and fun to type.

To generate files from templates using the Razor syntax you need:

  • To be in .NET 4,
  • References to the CodeFluent.Runtime.dll and CodeFluent.Model.Common.dll (versions strictly upper than 50401.587),
  • A reference to System.Web.Razor

As an example, here’s a template which loads from its context a string array containing all NBA teams, and lists them in a text file:

@ template engine=”razor”

Generated @System.DateTime.Now

    string[] nbaTeams = (string[])Context[“NbaTeams”];

Current NBA Teams:
@foreach (string team in nbaTeams) {
    <text>- @team</text>

Check-out this nice blog post for a quick reference on the Razor syntax.

Then here’s the code using CodeFluent’s Template Engine which runs the template and prints its output on the console:

class Program
    private static string[] _nbaTeams = { /* All Teams...*/ };

    static void Main(string[] args)
        Template template = new Template();
        template.Load("Sample.txt", TemplateOptions.Default);
        Hashtable context = new Hashtable();
        context["NbaTeams"] = _nbaTeams;
        template.Run(Console.Out, context);

Here’s the output:

Generated 04/12/2011 14:42:13

Current NBA Teams:
        – Boston Celtics
        – New Jersey Nets
        – New York Knicks
        – Philadelphia 76ers
        – Toronto Raptors
        – Dallas Mavericks
        – Houston Rockets
        – Memphis Grizzlies
        – New Orleans Hornets
        – San Antonio Spurs
        – Chicago Bulls
        – Cleveland Cavaliers
        – Detroit Pistons
        – Indiana Pacers
        – Milwaukee Bucks
        – Denver Nuggets
        – Minnoseta Timberwolves
        – Portland Trail Blazers
        – Oklahoma City Thunder
        – Utah Jazz
        – Atlanta Hawks
        – Charlotte Bobcats
        – Miami Heat
        – Orlando Magic
        – Washington Wizards
        – Golden State Warriors
        – Los Angeles Clippers
        – Los Angeles Lakers
        – Phoenix Suns
        – Sacramento Kings

Categories: Templates Tags: ,

Default Persistence Server

April 11, 2011 3 comments

By default CodeFluent Entities uses the following connection string:

Application Name=[DefaultNamespace];server=[DefaultPersistenceServer];database=[DefaultNamespace];Integrated Security=true

Where [DefaultNamespace] is the default namespace of your CodeFluent Entities project, and [DefaultPersistenceServer] the default persistence server. By default, the default persistence server is configured to be

Of course, you can override the default connection string at the project level thanks to the Default Connection String property (defaultConnectionString attribute in XML):


Or at the producer level by specifying its connection string explicitly:


However, to keep your model as portable as possible the best practice is definitely that each developer sets his default persistence server to their server. To set this up, you need to:

  • run Visual Studio with administrator privileges,
  • get in Tools > Options… > CodeFluent Entities,
  • in the advanced tab of the property grid (click the button with the yellow plus sign to access it), set the Default Persistence Server property to your server.


Doing this ensures the default connection string used by CodeFluent Entities is valid. As a consequence, developers won’t have to override the default connection string in their models anymore, and this way a model can easily be shared between one another.


Blob Storage

April 8, 2011 Leave a comment

As announced in this previous post, a couple builds ago we released a new feature which lets you store your Binary Large Objects (a.k.a. blobs) in Windows Azure’s Blob Storage instead of inside your database.

As seen in this video, developers can now specify through their application configuration, at run time and without having to generate over nor compile over their sources, where they’d like their blobs to be loaded and stored from. Available configurations or either to store their blobs in database, in a Windows Azure Blob Storage Account, or on the server’s file system.

Here’s a set of application configuration illustrating how to configure the runtime where to store your blobs.

Here’s the default configuration of my Sample application: no specific binary service is specified, blobs are stored in my database.

     <section name="Sample"type="CodeFluent.Runtime.CodeFluentConfigurationSectionHandler, CodeFluent.Runtime" />
  <Sample connectionString="server=(local);database=Sample;Trusted_Connection=true" />

Now here’s the configuration but modified to use the Windows Azure Blob Storage for all my entities:

<Sample connectionString="server=(local);database=Sample;Trusted_Connection=true" binaryServicesTypeName="azure"
cloudStorageAccountConnectionString="DefaultEndpointsProtocol=http;AccountName=MyAccount;AccountKey=9K5cXEs+9zEcBXz9gqjp==" />

And now here’s the equivalent but to store them on the file system:

<Sample connectionString="server=(local);database=Sample;Trusted_Connection=true" binaryServicesTypeName="filesystem" fileSystemBlobStorageRootPath="C:\Blobs" />

Please note that the binary service both for file system and Windows Azure blob storage can be specified per entity as well:

<Sample connectionString="server=(local);database=Sample;Trusted_Connection=true">
  <binaryServices entityFullTypeName="Sample.Customer" binaryServicesTypeName="fileSystem" fileSystemBlobStorageRootPath="C:\Blobs" />
Categories: Oracle Database, SQL Server, SQLAzure Tags: