In this post I’ll start from the NerdDinner application, which you can get from CodePlex (http://nerddinner.codeplex.com/). In the NerdDinner database I added the following sample stored procedure named “sp_SelectDinnersByCountry” that takes a county name as a parameter:
CREATE PROCEDURE [dbo].[sp_SelectDinnersByCountry]
(
@Country [nvarchar] (50)
)
AS
SET NOCOUNT ON
SELECT DISTINCT *
FROM Dinners
WHERE Country = @Country
RETURNFrom there, I then imported the NerdDinner database into a brand new CodeFluent Entities model (as detailed on CodeFluent Entities’ Get Started page) and now what I want to do is to reuse my existing stored procedure, instead of creating a new one using CFQL.
Select the “Dinner” entity and add the following new method:
Now that our method is created we need to specify:
- it’s name in the persistence layer as my stored procedure has a different name than the one in my model,
- it’s return type (by default raw methods are void),
- mark my method so it’s not generated by the SQL Server Producer,
As a consequence the Business Object Model Producer will generate a SelectByCountry method, which calls the sp_SelectDinnersByCountry stored procedure, and returns a DataSet, so now in my app I can do something like this:
System.Data.DataSet ds = Dinner.SelectByCountry("FRANCE");Hope this helps,
Carl