What’s new with CodeFluent Entities 773?
This new build includes one new feature : Database producers now support custom COUNT methods expression (including DISTINCT).
Until now, CodeFluent Entities could only generate COUNT(*) statement using the CFQL COUNT method. This new version (build 773) introduce new XML attributes in order to let you change the generated count expression. For instance you can now generate the following SQL code:
SELECT COUNT(DISTINCT Customer_Name) FROM Customer
This is possible by using the new ‘countExpression’ xml attributes. The value of this attribute will be copied as is into the SQL COUNT statement.
As you are setting raw SQL, countExpression attribute is database producer specific, this means you have to set it once by database producer you use (SQL Server, Oracle, MySQL, and PostgreSQL).
<cf:method name="CustomByName" body="COUNT(Name) WHERE Name STARTSWITH @Name" xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1" cfps:countExpression="DISTINCT $Customer::Name$" xmlns:cfor="http://www.softfluent.com/codefluent/producers.oracle/2009/1" cfor:countExpression="DISTINCT $Customer::Name$" xmlns:cfpg="http://www.softfluent.com/codefluent/producers.postgresql/2012/1" cfpg:countExpression="DISTINCT $Customer::Name$" xmlns:cfmy="http://www.softfluent.com/codefluent/producers.mysql/2012/1" cfmy:countExpression="DISTINCT $Customer::Name$" />
This model will produce the following procedure:
CREATE PROCEDURE [dbo].[Customer_CountByName] ( @Name [nvarchar] (256) ) AS SET NOCOUNT ON SELECT COUNT(DISTINCT [Customer].[Customer_Name]) FROM [Customer] WHERE ([Customer].[Customer_Name] LIKE (@Name + '%')) RETURN GO
Note that Target Name Transformation (TNT) in countExpression is supported. Target Name Transformation (TNT) is a very powerful and important feature of CodeFluent which allows developers to use the names of entities, properties, and views inside SQL snippets and raw queries. Therefore, it allows developers to use actual output names of objects (tables, columns, views) with the support of the defined naming convention:
If you are not a current customer, you can always download our free evaluation and see it in action. Remember that you can follow the latest new features and bug fixes of CodeFluent Entities subscribing to this RSS Feed.
The R&D Team