CodeFluent Entities Documentation
Microsoft SQL Server Producer
See Also Send comments on this topic.
CodeFluent Entities > Architect Guide > Generating > Microsoft SQL Server Producer

Glossary Item Box

The Microsoft SQL Server Producer is a persistence producer and will generate from your model a Microsoft SQL Server database.

Using a CodeFluent Entities model, one can define his business concepts, relations from a concept to another as well as the logic in which they all interact with one another. From this platform independent model, a meta-model is built which will be translated by producers to generate platform specific code.

From this meta-model, the Microsoft SQL Server Producer generates a set of T-SQL scripts which create data objects; translating platform independent concepts (e.g. a Customer entity) into platform specific code (e.g. a Customer table). On the same principles:

All those data objects are created by the generated scripts. By default, those generated scripts are ran automatically at production time.

Furthermore, the Microsoft SQL Server Producer has a differential engine, meaning that between generations the database isn't dropped and created over but altered (columns and procedures added, types changed). This feature is a key feature, since it allows to generate continuously, driving developments from the model. 

The Diff Engine uses SQL Distributed Management Objects (SQL-DMO), therefore, if using SQL Server 2008 or SQL Server 2008 R2, you'll need to install them on your server to benefit from this feature.

You can download them 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

The SQL-DMO dependency is planned to be removed towards 2011 - Q2.

Example

This example demonstrates how to configure the Microsoft SQL Server Producer to generate the persistence layer. 

Several configuration parameters are specified:

  • connectionString: the connection string indicating the server, database, and authentication mode. 
  • targetVersion: several SQL Server versions are supported (2000, 2005, 2008). Use this attribute to target a specific SQL Server version.
  • produceViews: views aren't produced by default. Use this attribute to enable or disable this feature.
  • produceSchemas: by default all tables are generated in the dbo schema. In the model you can specify a schema on an entity. The Microsoft SQL Server can generate a persistence schema from the modeled schema. This behavior can be enabled or disabled by the produceSchemas attribute.
Note: In this example, Vehicle and VehiclePricing entities are declared in the Referential schema.
Model Copy Code
<cf:project xmlns:cf="http://www.softfluent.com/codefluent/2005/1"
            defaultNamespace="CodeFluent">
 
    <!-- Microsoft SQL Server Producer -->
    <cf:producer name="Microsoft SQL Server Producer"
                 typeName="CodeFluent.Producers.SqlServer.SqlServerProducer, CodeFluent.Producers.SqlServer">
        <cf:configuration connectionString="Server=localhost;Database=CodeFluent;Integrated Security=true"
                          targetDirectory="..\Generated\Sql2005"
                          targetVersion="Sql2005"              
                          produceViews="true"  
                          produceSchemas="true"/>
    </cf:producer>
 
    <!-- Entities -->
    <Vehicle namespace="{0}.Referential" schema="Referential">
        <Id typeName="int" />
        <Label typeName="string" />
    </Vehicle> 
    <VehiclePricing namespace="{0}.Referential" schema="Referential">
        <Id typeName="int" />
        <Vehicle typeName="{0}.Referential.Vehicle" />
        <ApplicationDate typeName="datetime" />
        <Price typeName="float" />
    </VehiclePricing>
 
</cf:project>
Note: the connection string can also be defined at the project level so that the same connection string is used by several producers. In such cases, there is no need to declare a connection string in the Microsoft SQL Server Producer configuration.

Microsoft SQL Server Producer Output

The SQL Server Producer has generated:

  • the table Customer with the primary key Customer_Id
  • the stored procedures Customer_Load, Customer_Save and  Customer_Delete

 


 

See Also