SQL Hints

CodeFluent allows developers to specify SQL specific hints on its methods.

For instance, doing as so:

<cf:project xmlns:cf=http://www.softfluent.com/codefluent/2005/1″
xmlns:cfps=http://www.softfluent.com/codefluent/producers.sqlserver/2005/1″>
<Customer>
<Id />
<Name />
<cf:method name=“LoadByName” body=“load(string name) Where Name=@name” cfps:tableHint=NOLOCK />
</Customer>
</
cf:project>

Will generate a T-SQL stored procedure with the NOLOCK hint applied to the Customer table.

A recurring question that we have is “which SQL Server hints does CodeFluent support?“. Well the answer is very straightforward: all of them! Since, the applied hint isn’t inferred from the specified value, it means that regarding CodeFluent, you could specify anything! All that matters is that the specified hint is actually supported by the targeted platform.

For an exhaustive hint list, please check-out your SQL Server’s corresponding documentation:

CodeFluent R&D Team

CodeFluent and the SqlGeography Type

Although there is not a geography type in CodeFluent (as this is too specific to SQL Server 2008), you can still use the new SQL 2008 geography type today.

First you need to declare the target type in the CodeFluent SQL Server Producer (with the ‘cfps:dataType’ attribute). Then, optionally, you can declare a computed companion property that will hold the data as the corresponding SQL Server 2008 .NET Type: SqlGeography.

It will work because these types can be transferred back and forth as arrays of bytes. Here is a sample model that does it:

Code:


<cf:project xmlns:cf="http://www.softfluent.com/codefluent/2005/1"
defaultNamespace="Test"
xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1">

<Address>
<Id />
<RawSpatialLocation cfps:dataType="geography" typeName="byte[]" maxLength="-1" />
<SpatialLocation typeName="Microsoft.SqlServer.Types.SqlGeography" persistent="false">
<cf:rule typeName="OnGet" />
<cf:rule typeName="OnAfterSet" />
<cf:snippet name="SpatialLocation">

private void OnGetSpatialLocation()
{
_spatialLocation = new Microsoft.SqlServer.Types.SqlGeography();
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(RawSpatialLocation))
{
using (System.IO.BinaryReader reader = new System.IO.BinaryReader(stream))
{
_spatialLocation.Read(reader);
}
}
}

private void OnAfterSetSpatialLocation(Microsoft.SqlServer.Types.SqlGeography spatialLocation)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
using (System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream))
{
_spatialLocation.Write(writer);
_rawSpatialLocation = stream.ToArray();
}
}
}
</SpatialLocation>
</Address>
</cf:project>

NOTE1: make sure Microsoft.SqlServer.Types.dll is referenced for the project to compile.

NOTE2: all this is valid for the SqlGeography, SqlGeometry and SqlHierarchyId types.

The next version of CodeFluent will allow you to directly declare this:

Code:


<cf:project xmlns:cf="http://www.softfluent.com/codefluent/2005/1"
defaultNamespace="Test"
xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1"
assemblyPaths="c:\temp\Microsoft.SqlServer.Types.dll"> <!-- adapt this to your machine -->

<Address>
<Id />
<SpatialLocation cfps:dataType="geography" typeName="Microsoft.SqlServer.Types.SqlGeography, Microsoft.SqlServer.Types" />
</Address>
</cf:project>

CodeFluent R&D Team

Business Object Model Now Supports Oracle Databases

Support of Oracle Databases at Business Object Model (BOM) level was now added using Microsoft’s (System.Data.OracleClient) and Oracle’s (Oracle.DataAccess.Client) providers.

To enable this support, neither extra attributes nor any modifications in the BOM are required: all one needs to do is to update its connection string declaration.

Example:

  1. .NET Oracle Provider:

    <[DefaultNamespace] connectionString=”Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MYORACLESERVER)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));user id=HR;password=hr” persistenceTypeName=”System.Data.OracleClient.OracleConnection, System.Data.OracleClient”/>

     
     

  2. ODP.NET Oracle Provider:

    <[DefaultNamespace] connectionString=”Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MYORACLESERVER)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));user id=HR;password=hr” persistenceTypeName=”Oracle.DataAccess.Client.OracleConnection, Oracle.DataAccess.Client”/>

 
 

The CodeFluent runtime will automatically add the cursor parameter which is required to read Oracle Server procedures.

Even though the Oracle Server Producer is still on its way, this provides a way to map a generated BOM onto an Oracle persistence layer.

CodeFluent R&D Team

CodeFluent and Enterprise Architect: the first stone towards importing UML model.

The R&D team has just delivered an internal release of CodeFluent that demonstrates how to import an UML model designed with Sparx Systems Enterprise Architect software. Starting from an input Abstract Class Model designed through EA, we are able to import the entire entities diagram as a CodeFluent model. The following screenshot depicts a sample EA model with the following business entities: Order, Order Status, Account, Transaction, Line Item and Stock Item:

 
 

Let’s now have a look of the generated CodeFluent model using the forthcoming CodeFluent modeler:

 
 

The Enterprise Architect importer is still at an early stage of the development cycle but we will work hard during the forthcoming months to deliver a complete solution for importing UML models to CodeFluent. You will then be able to generate ready to use components (from database to UI such as SharePoint) on Microsoft technologies.

Ease your life, use CodeFluent .

Stay tuned!

Omid Bayani.

Generate a documentation of your CodeFluent model using CodeFluent API

As a CodeFluent architect, you may wonder how you could generate a human readable document of your model without having to write it manually. The answer is to use the CodeFluent template engine. This article gives you some basic understanding of how to write a template to generate a Rich Text File document (containing formatting, logo, etc) and also provide a ready to use template that you can customize according to your own needs.

All projects developed with CodeFluent are based on models. A model is always composed of a set of entities. These entities contain properties, methods, rules, etc. In order to provide to people outside of the development team, an explanation of the CodeFluent model in a formatted document could be appreciated. To generate this document, a developer can use the template associated with this article. Nevertheless, the CodeFluent model must be enriched with the desired documentation using CodeFluent message with a dedicated attribute. This attribute is available at entity, property and method levels. Here’s a simplified sample model:

<cf:entity
name=Customer>

<cf:message
class=_doc>Simple customer</cf:message>

<cf:property
name=Id>

<cf:message
class=_doc>Technical identifier</cf:message>

</cf:property>

<cf:property
name=Phone>

<cf:message
class=_doc>Phone number of the customer</cf:message>

</cf:property>

<cf:method
name=LoadByPhoneNumber
body=load(Phone) where Phone = @Phone>

<cf:message
class=_doc>Load customer by phone number</cf:message>

</cf:method>

</cf:entity>

By the way, after generation, the properties and methods of the generated business object layer (BOM) will contain new tags in standard .NET format as illustrated hereafter:

Entity level

///
<summary>Customer entity</summary>

public
partial
class
Customer

Property level

///
<summary>Phone number of the customer</summary>

public
string Phone {

get { return
this._phone; }

set { this._phone = value; this.EntityState = CodeFluent.Runtime.CodeFluentEntityState.Modified; this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs(“Phone”)); }

}

Method level

///
<summary>Load customer by phone number</summary>

public
static System.Data.IDataReader PageDataLoadByPhoneNumber(CodeFluent.Runtime.PageOptions pageOptions, string phone)

Using CodeFluent template engine, we developed a template to generate a full documentation. Note that the CodeFluent Template producer supports text files format such as RTF files. To describe our example, we created a RTF file named [Template]Model documentation.rtf with Microsoft Word. We then edited our template and added some code using CodeFluent API.

Let’s quickly describe the template inside:

  • First, retrieve all entities of the model:

    EntityCollection entities = Producer.Project.Entities;

  • For each entity in the model, retrieve the comment at entity level using GetMessage method:

    CultureInfo currentCulture = new
    CultureInfo(1033);

    Message messageGlobal = entity.GetMessage(“_doc”, currentCulture);

  • And do the same for methods and properties:

    CultureInfo culture = new
    CultureInfo(1033);

    IList properties = new
    List<Property>();

    IList methods = new
    List<Method>();

    foreach (Property property in entity.Properties)

    {


    Message messageProperty = property.GetMessage(“_doc”, currentCulture);


    if (messageProperty != null)


    properties.Add(property);

    }

    foreach (Method method in entity.Methods)

    {


    Message messageMethods = method.GetMessage(“_doc”, currentCulture);


    if (messageMethods != null)


    methods.Add(method);

    }

You can notice that we use the english culture (1033) but you can localize your documentation using “cultureName” attribute inside your model. For example, if you want to translate your comment into french, proceed as follows:

<cf:message
class=_doc
cultureName=fr>Entité client</cf:message>

Then, you can get the message value:

[%foreach (Property property in properties) { Message currentMessage = property.GetMessage("_doc", currentCulture);%] [%= currentMessage.Value %] [%}%]

Let’s have a look at the generated RTF document:

How to use the provided template?

Put your template file into a directory of your choice and use the “template producer” in your project in order to produce the output documentation file:

<cf:producer
name=Template Producer

typeName=CodeFluent.Producers.CodeDom.TemplateProducer, CodeFluent.Producers.CodeDom>


<cf:configuration
sourceDirectory=Templates\Doc
targetDirectory=.\Generated\
outputEncoding=iso-8859-1/>

</cf:producer>

We hope that from now on, all your CodeFluent projects will be fully documented .

This article is only a little overview of CodeFluent templating mechanism and CodeFluent API features. You will find the sample code and the generated documentation inside the following zip code. You can find the corresponding materials here.

Antoine Diekmann – SoftFluent

CodeFluent Visual Studio Project Templates

Hi guys,

Sick and tired of creating the same set of projects, xml, and batch file each time you’re starting a new CodeFluent project using Visual Studio?

Well I got some good news for you: we’re releasing a set of project templates for Microsoft Visual Studio 2008 that creates the whole project infrastructure based on the targeted application type. For instance, if you want to create a web site using CodeFluent pick the CodeFluent Base Solution which will create:

  1. a “Design” project containing: a batch file to generate your model, and your CodeFluent Model with a producer part already configured to produce code in the targeted projects,
  2. a “Persistence” project containing the to-be-generated persistence scripts so that you can view and source control them easily,
  3. and a “Business Object Model” project named from the default namespace which will contain the to-be-generated BOM classes.

Each project already contains all required references or extra actions to build/execute properly.

Here are the available solution templates:

  • CodeFluent Base Solution (Design + Persistence + BOM),
  • CodeFluent Services Solution (Design + Persistence + BOM + SCOM + Configuration files),
  • CodeFluent Generated Web Site Solution (Design + Persistence + BOM + CF Generated Web Site),
  • CodeFluent Office Synchronizable Lists Solution (Design + Persistence + BOM + Office Sync Lists),
  • CodeFluent Silverlight Solution (Design + Persistence + BOM + SLOM + Configuation files),
  • CodeFluent Full Solution (All projects listed above)

You’ll find everything here: Visual Studio 2008 Starter Kit for CodeFluent.

Enjoy!

Carl

POCO with CodeFluent

POCO support should not be a feature, it should be builtin. It has always been possible with CodeFluent because the classes the product generates derive from System.Object (the default mode), or from any class you want, not from some framework class that you can’t change. Note also we don’t use Reflection mechanisms. This is fairly easy to do, just add the baseTypeName attribute, and specify the base class full name, like this :

<cf:project defaultNamespace=”CodeFluentSamples”>

   <Employee baseTypeName=”MyNamespace.MyBaseClass“>

      <EmpId typeName=”int”/>

   </Employee>

</cf:project>

What’s in CodeFluent?

For those of you wondering what really is in the product, here is a graph generated using the cool Visual NDepend tool, for a total of more than 110000 Lines of Code (metric defined by NDepend). What’s interesting is to categorize all these nice but hardly visible gray boxes. This is what we have done in the next image. 

   This is the same box, but with CodeFluent features here arranged in 4 big categories: Import (reusing existing model or databases, and avoid loosing existing investments), Modeling (including the soon-to-come visual tools), Production (the real meat!) and Runtime support. As you can see, Modeling is still quite big, especially the in-memory model (the biggest box of all) built after parsing time. Runtime support has grown recently due to the recent SharePoint (WSS/MOSS) and Silverlight 2 support.   CodeFluent R&D Team