CodeFluent Entities: Customizing the Method Body
CodeFluent Entities provides “Methods” which allows developers to define custom data accessing methods (load, loadone, delete, count, search) which persistence producers will translate into stored procedures.
For instance, the following method:
Will generate the following stored procedure:
CREATE PROCEDURE [dbo].[Setting_LoadByName]
@Name [nvarchar] (256)
SET NOCOUNT ON
SELECT DISTINCT [Setting].[Setting_Id], [Setting].[Setting_Name], [Setting].[Setting_Value] FROM [Setting]
WHERE ([Setting].[Setting_Name] = @Name)
You can also create what we call Raw methods which are platform specific code such as T-SQL or PL-SQL, but you can also mix both, that is to say create a CFQL method so upper layers benefit from the out-of-the-box features provided by such methods and just override the actual body of the stored procedure.
For instance say you wanted to create a topped method which the number of returned rows can be passed to the method. The “TOP” statement doesn’t exist in CFQL (see TOP in CFQL for more information) so a way to do this would be to mix CFQL and T-SQL for instance.
To do so, start by defining your CFQL body:
And then define the Raw Text property of the body (select your method, and click on the “Bodies” property in the property grid):
Once this is done, if you build your model, the stored procedure quoted hereunder will be generated, and in upper layers your method will look just as expected (returning a SettingCollection, mapping returned columns to properties, and taking an int maxCount parameter):
CREATE PROCEDURE [dbo].[Setting_BoundedLoadAll]
SET NOCOUNT ON
SELECT TOP(@maxCount) * from Setting