Quantcast
Channel: SQL Azure – The CodeFluent Entities Blog
Viewing all articles
Browse latest Browse all 15

CodeFluent Entities: Customizing the Method Body

$
0
0

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



Viewing all articles
Browse latest Browse all 15

Trending Articles