Home > Developing Using CodeFluent Entities, Oracle Database, SQL Server, SQLAzure > CodeFluent Entities: Customizing the Method Body

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:

image

Will generate the following stored procedure:

CREATE PROCEDURE [dbo].[Setting_LoadByName]
(
@Name [nvarchar] (256)
)
AS
SET NOCOUNT ON
SELECT DISTINCT [Setting].[Setting_Id], [Setting].[Setting_Name], [Setting].[Setting_Value] FROM [Setting]
    WHERE ([Setting].[Setting_Name] = @Name)

RETURN

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:

image

And then define the Raw Text property of the body (select your method, and click on the “Bodies” property in the property grid):

image

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]
(
@maxCount [int]
)
AS
SET NOCOUNT ON
SELECT TOP(@maxCount) * from Setting
RETURN

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s