Author Archive

Table-Valued Parameters: Basics

February 11, 2015 Leave a comment

First, what is Table-Valued Parameters ?

Table-valued parameters provide an easy way to marshal multiple rows of data from a client application to SQL Server without requiring multiple round trips or special server-side logic for processing the data.

You can use table-valued parameters (TVP) to send multiple rows of data to a Transact-SQL statement or a routine, such as a stored procedure or function, without creating a temporary table or many parameters.

Great news, you can use TVP with CodeFluent Entities! Let’s see how you can use TVP to bulk load rows based on a list of id.

Create a new CFQL method:

Note the usage of “[]” after the type name. The generated method is:

public static CustomerCollection LoadByIds(System.Guid[] ids)

And the generated stored procedure:

CREATE TYPE [dbo].[cf_type_Customer_LoadByIds_0] AS TABLE (
 [Item] [uniqueidentifier] NULL)
CREATE PROCEDURE [dbo].[Customer_LoadByIds]
 @ids [dbo].[cf_type_Customer_LoadByIds_0] READONLY
DECLARE @_c_ids int; SELECT @_c_ids= COUNT(*) FROM @ids
SELECT DISTINCT [Customer].[Customer_Id], [Customer].[Customer_FirstName], [Customer].[Customer_LastName], [Customer].[Customer_DateOfBirth]
    FROM [Customer]
    WHERE [Customer].[Customer_Id] IN (((SELECT * FROM @ids)))


Table-Valued Parameters require at least SQL Server 2008. Don’t forget to change the target of the SQL Server producer to use at least this version. Additionally set Legacy String Array Mode to false.

Additionally set Legacy String Array Mode to false.


Happy coding,

The R&D Team.

WPF Universal Converter

February 3, 2015 Leave a comment

When you create an application using WPF, you often have to write converters to change one value to the desired type. The .NET Framework already provides some basics converter such as BooleanToVisibilityConverter. These converters are very specifics and not configurable. For example you cannot change the visibility from Collapsed to Hidden. We do not want to spend time to write common converter so we create the UniversalConverter.

The converter is located in the CodeFluent.Runtime.dll or CodeFluent.Runtime.Client.dll. Please use the Nuget Package Manager to add this Package on your project:


Let’s see how to use it!

Basic conversion

    <windows:UniversalConverter x:Key="TypeConversionUniversalConverter" />

<CheckBox IsChecked="{Binding Converter={StaticResource TypeConversionUniversalConverter},
   Mode=OneWay}" DataContext="true"/>
<CheckBox IsChecked="{Binding Converter={StaticResource TypeConversionUniversalConverter}, 
   Mode=OneWay}" DataContext="yes"/>

UniversalConverter uses ConvertUtilities to convert the value to the desired type so string values “true” and “yes” will be converted to the Boolean value “true”.

Switch Case syntax

You can create a list of cases to fit all your needs. For instance:

<windows:UniversalConverter x:Key="BooleanToVisibilityConverter">
        <cfr:UniversalConverterCase Operator="Equal" Value="True" C
  onvertedValue="Visible" />
        <cfr:UniversalConverterCase Operator="Equal" Value="False" 
  ConvertedValue="Collapsed" />

As a C# switch you can set a default value:

<cfr:UniversalConverter x:Key="BooleanToVisibilityConverter" DefaultValue="Visible">
        <cfr:UniversalConverterCase Operator="Equal" Value="False" 
  ConvertedValue="Collapsed" />

There are currently 13 operators:

  • Equal,
  • NotEqual,
  • GreaterThan,
  • GreaterThanOrEqual,
  • LesserThan,
  • LesserThanOrEqual,
  • Between: minimum and maximum value included => [min:max[,
  • StartsWith,
  • EndsWith,
  • Contains,
  • IsType: type match exactly,
  • IsOfType: type or direved types,
  • JavaScript: Yes, you can use JavaScript to evaluate a condition!

And some options:

  • StringComparison
  • Trim
  • Nullify

Here’s a list of examples using different operators:

Check if a string contains NewLine using JavaScript

<cfr:UniversalConverter x:Key="HasMultipleLinesConverter" DefaultValue="False">
        <!--look for a CR or LF in the string string-->
        <cfr:UniversalConverterCase Value="/\r|\n/.exec(Value)!=null" 
  ConvertedValue="True" Operator="Javascript" />

Set error message background and foreground color

<cfr:UniversalConverter x:Key="ErrorTextBackgroundConverter" DefaultValue="Red">
        <cfr:UniversalConverterCase Value="" ConvertedValue="Transparent" />
<cfr:UniversalConverter x:Key="ErrorTextForegroundConverter" DefaultValue="White">
        <cfr:UniversalConverterCase Value="" ConvertedValue="Black" />

Test if a value is over 21

<cfr:UniversalConverter x:Key="IsOver21Converter" DefaultValue="false">
        <cfr:UniversalConverterCase Operator="GreaterThanOrEqual" Value="21" 
  ConvertedValue="true" Options="Convert" />

Is teenager

<cfr:UniversalConverter x:Key="IsTeenagerConverter" DefaultValue="false">
        <cfr:UniversalConverterCase Operator="Between" MinimumValue="13" 
  MaximumValue="20" ConvertedValue="true" Options="Convert" />

Compare types

<cfr:UniversalConverter x:Key="TypeConverter" DefaultValue="false">
        <cfr:UniversalConverterCase Operator="IsType" Value="System.String" 
  ConvertedValue="Type = String" />
        <cfr:UniversalConverterCase Operator="IsType" Value="System.Int32" 
  ConvertedValue="Type = int" />
        <cfr:UniversalConverterCase Operator="IsOfType" 
  Value="BaseClass, MyAssembly" ConvertedValue="Type is of type BaseClass" />

Is empty

<cfr:UniversalConverter x:Key="IsEmptyConverter" DefaultValue="Not empty">
        <cfr:UniversalConverterCase Operator="Equal" Options="Trim, Nullify" 
  ConvertedValue="Empty" />

<TextBox x:Name="TextBox"/>
<TextBlock Text="{Binding ElementName=TextBox, Path=Text, 
  Converter={StaticResource IsEmptyConverter}}" />

If you need more examples, please let us know. Our team will be happy to help you J.

Happy converting,

The R&D team

Azure Cache Manager and Redis Cache Manager

January 27, 2015 Leave a comment

CodeFluent Entities allows to cache request results by using the Cache sub-producer:

CodeFluent entities provides out of the box three types of Cache implementations:

  • Simple Cache Manager, based on the ASP .NET cache (that can be used outside of ASP.NET) (CodeFluent.Runtime.Caching.SimpleCacheManager, CodeFluent.Runtime)
  • Simple Localized Cache Manager, a sub-class of the Simple Cache Manager that can manage localized keys (CodeFluent.Runtime.Caching.LocaleCacheManager, CodeFluent.Runtime)
  • Enterprise Library Cache Management, you must install the Enterprise Library in order to use it (CodeFluent.Runtime.Caching.EnterpriseLibraryCacheManager, CodeFluent.Runtime)

You can specify the type of cache you want to use on the “Runtime Cache Type Name” attribute (the full type name). You can use a different cache systems by scope (entity, method).

Microsoft Azure introduces two cache services: Azure Managed Cache Service and Azure Redis cache (currently in preview).

Azure Cache is a family of distributed, in-memory, scalable solutions that enables you to build highly scalable and responsive applications by providing you super-fast access to your data. We offer the following types of Azure Cache:

  • Azure Redis Cache: Built on the open source Redis cache. This is a dedicated service, currently in Preview.
  • Managed Cache Service: Built on App Fabric Cache. This is a dedicated service, currently in General Availability.
  • In-Role Cache: Built on App Fabric Cache. This is a self-hosted cache, available via the Azure SDK.


CodeFluent Entities already provide support some Azure features such as Azure Table and Azure Blob Storage, and we decided to continue our efforts to help our customers to use Microsoft Azure. This is why we release two new cache managers:

  • Redis Cache Manager
  • Azure Cache Manager

How to use Azure Redis Cache?

Download the Redis CacheManager from GitHub and add it to your project. You also need to add the following NuGet package: StackExchange.Redis.

Now you can change the cache producer configuration:

Then build the model.

Finally you have to configure the cache manager with the configuration file (app.config or web.config) to use your Redis server:

    <add key="SoftFluent.Samples.RedisCache.Caching.RedisCacheManager.Configuration"
 value=",allowAdmin=true,ssl=true,password=password" />

    <add key="SoftFluent.Samples.RedisCache.Caching.LocaleRedisCacheManager.Configuration"
 value=",allowAdmin=true,ssl=true,password=password" />

Note: if you use the Localization Aspect, you have to use SoftFluent.Samples.AzureCache.Caching.LocaleRedisCacheManager.

How to use Azure Cache Service and In-RoleCache?

Managed Cache Service and In-Role Cache use the same API, so you can use the same cache manager.

Download the CacheManager from GitHub and add it to your project. You also need to add the following NuGet package: Microsoft.WindowsAzure.Caching. Now you can change the cache producer configuration:

Then build the model.

Finally you have to configure the azure cache client:

If you are not using the “default” cache, you can set the client name and cache name in the configuration file (app.config or web.config):

    <add key="SoftFluent.Samples.AzureCache.Caching.AzureCacheManager.ClientName"

    <add key="SoftFluent.Samples.AzureCache.Caching.LocaleAzureCacheManager.CacheName"

Note: if you use the Localization Aspect, you have to use SoftFluent.Samples.AzureCache.Caching.LocaleAzureCacheManager.

If you think we can add some useful functionalities to CodeFluent Entities, please share your idea on the forum.

Happy caching,

The R&D Team

Categories: Cache Tags: , ,

How to parse a command line?

January 16, 2015 1 comment

The CodeFluent Runtime offers to applications a clean and concise class for manipulating command line arguments and related tasks. Add the nugget package and refers the CommandLineUtilities class.

This class parses your command line arguments, find all parameters starting with – or / and all the values linked. I assumed that a value could be separated from a parameter with a : or a =.

During this article we are going to simulate this execution:

/Program.exe –ProductName:Word /SendEmail=true -amount:10.5


Gets a positioned argument from the command line and convert it to the type of the default value. If the argument is not found or if the value cannot be converted to the expected type, it returns the default value (internally it uses ConvertUtilities).

CommandLineUtilities.GetArgument(name:"ProductName", defaultValue:string.Empty); // -> “Word”
CommandLineUtilities.GetArgument(name:"ProductName", defaultValue:0); // -> 0
CommandLineUtilities.GetArgument(name:"SendEmail", defaultValue:false); // -> True
CommandLineUtilities.GetArgument("amount", double.MaxValue, new CultureInfo("en-US")); // -> 10.5D


Determines whether the argument is specified in the command line.

CommandLineUtilities.HasArgument(name:"ProductName"); // -> True
CommandLineUtilities.HasArgument(name:"debug"); // -> false


List all arguments, the name will be the key.

// -> {{“ ProductName”,”Word”},{“SendEmail”,”true”}}


Gets a value indicating whether help was requested.

// /Progam.exe /HELP
CommandLineUtilities.HelpRequested; // -> True

Happy CLI-ing !

The R&D Team.

Custom Naming Convention

January 8, 2015 Leave a comment

Since CodeFluent Entities infers a meta-model from your model, before any producer is called to generate a single line of code, a full representation of your application is in-memory. Thanks to this inference step and the resulting meta-model, developers can apply application wide changes.

One of the possible application wide changes is to change the way all database objects are named through a naming convention. By default a set of naming conventions are provided by CodeFluent Entities:

  • FormatNamingConvention
  • LowerCaseNamingConvention
  • UpperCaseNamingConvention
  • DecamelizeNamingConvention
  • DecamelizeLowerCaseNamingConvention
  • DecamelizeUpperCaseNamingConvention

And you can also implement your own naming convention to fit your needs as we’ll see in this post.

Create the custom Naming Convention

The naming convention is a class so we create a class library project and add references to

  • CodeFluent.Runtime.dll
  • CodeFluent.Model.dll
  • CodeFluent.Model.Common.dll

Those DLL are located in the installation folder of CodeFluent Entities.

Create a class that implements IProjectNamingConvention or inherits from an existing Naming Convention:

using System.Collections;
using CodeFluent.Model.Common.Naming;
using CodeFluent.Model.Naming;
using CodeFluent.Model.Persistence;

namespace SoftFluent.Samples.CustomNamingConvention
    public class MyNamingConvention : FormatNamingConvention
        public override string GetName(INamedObject obj, IDictionary context)
            var procedure = obj as Procedure;
            if (procedure != null)
                if (procedure.Table != null &&
                    procedure.Table.Entity != null &&
                    procedure.Table.Entity.Store != null)
                    return procedure.Table.Entity.Store.Name + "_" + base.GetName(obj, context);

                if (procedure.Method != null &&
                    procedure.Method.Entity != null &&
                    procedure.Method.Entity.Store != null)
                    return procedure.Method.Entity.Store.Name + "_" + base.GetName(obj, context);

            return base.GetName(obj, context);

This naming convention prefix parameter name with the store name

Setting the naming convention

Add a reference in the CodeFluent entities project to your class library project:

Now you can open model project properties and set the naming convention with its full type name:


That’s all J Now all procedures are prefixed by the store name:

Happy naming,

The R&D Team

What’s new with CodeFluent Entities 801?

December 19, 2014 Leave a comment

Today we release the build 801. This build includes lots of new features:

Cache Producer and array


The Cache Producer creates a unique key for each method call based on the method name and its parameter values:

cacheKey = SimpleCacheManager.BuildCacheKey("ad5a4755bc1df9345e1a73e2ae38",
                                             pageIndex, pageSize, 
                                             pageOptions, ids);

The BuildCacheKey method handles common parameter types such as String, Boolean, Integer, DateTime, etc. But it does not handle complex types such as array for the simple reason that there are many ways to handle them. We decided to let you handle those cases as you want depending of your context. We introduce a new optional parameter “Build Cache Key Method Name”:

The generated code will be:

cacheKey = CustomerCollection.CustomBuildCacheKey("ad5a4755bc1df9345e1a73e2ae38",
                                                   pageIndex, pageSize, 
                                                   pageOptions, ids);

This way you can create the key the way you want!

Use existing .NET enumeration and type


CodeFluent Entities can reuse existing .NET enumeration or .NET type. The modeler now lets you add those type on the surface:

The enumeration and all its values will be added to the surface:

The same apply with .NET type such as “System.Drawing.Point”

SQL Server Producer & “Nullable” Table Value Parameters


When you create a CFQL method with persistence nullable array parameter:

ids?) WHERE Id IN (@ids)

The SQL Server producer generates the following code:

DECLARE @_c_ids int; SELECT @_c_ids= COUNT(*) FROM @ids
IF(@_c_ids = 0)
    SELECT [Customer].[Customer_Id], [Customer].[Customer_FirstName], 
        FROM [Customer]
    SELECT [Customer].[Customer_Id], [Customer].[Customer_FirstName], 
        FROM [Customer]
        WHERE [Customer].[Customer_Id] IN (SELECT * FROM @ids)

IS NULL is translated to Array is empty because TVP cannot be NULL. We think this check is the most logical in this case.

Starter Wizard


Starter wizard supports new project templates:

Pivot Script improvements


The SQL Server Pivot Script producer has many new options to select what to produce (tables, procedures, functions, etc.):

Sorting Project Resources


Project resources grid allows to sort rows by name, class or value:

Visual Studio 2015 Preview


As we mentioned this week, CodeFluent Entities now supports Visual Studio 2015 Preview.


You can download this build here, or update your version using the Licensing tool. Remember that you can follow the latest new features and bug fixes of CodeFluent Entities subscribing to this RSS.

Happy downloading!

The R&D Team

Categories: News

Visual Studio 2015 Preview

December 15, 2014 Leave a comment

One month ago, we told you that CodeFluent Entities runs great on Visual Studio 2013 Community. The story continues and CodeFluent Entities now supports Visual Studio 2015 Preview.

visual studio 2015

Indeed, a preview of VS 2015 is available for those ready to dive into next-generation development tool. We’re especially excited to announce that you can create or open your CodeFluent Entities models directly from Visual Studio 2015 :


You can learn more about the new features of Visual Studio 2015 Preview here:

You can download the latest version of CodeFluent Entities here, or update your version using the Licensing tool. Remember that you can follow the latest new features and bug fixes of CodeFluent Entities subscribing to this RSS.

Happy downloading,

The R&D Team

Categories: News Tags:

Get every new post delivered to your Inbox.

Join 56 other followers