I'm trying to figure out how to obtain the results of a SQL Server stored procedure using Codefluent. I have a well developed CF project, but there is one very complicated stored procedure that I don't want to monkey around with.
Basically, the procedure takes a series of input parameters and returns rows from a table. From this standpoint it is fairly simple, though the underlying T-SQL is not. The column names returned are not the original column names in the underlying tables which is why I am also looking to use a raw CF procedure.
I've tried a variety of approaches. I created a view and a raw procedure - (the view inferred model seemed to like this one)
<cf:view autoLightweight="true" name="myLWview">
<cf:viewProperty name="field1" />
<cf:viewProperty name="field2" />
...
<cf:viewProperty name="fieldn" />
</cf:view>
<cf:method name="GetLog" returnTypeName="list(of myLWview)">
<cf:body text="RAW (parameter1, parameter2, ..., parametern)" rawText="select [field1], [field2], ... , [fieldn] from mySQLprocedure" language="tsql" />
</cf:method>
This fails on the ExecuteReader
call.
I'm sure it is something obvious I'm missing. Any advice would be greatly appreciated. Thanks!
Thanks to Mexiantou and Dave, this is the CF model (pattern) I created to obtain results from an MS-SQL stored procedure that is/was not created by the CF modeler.
First, I created a CF lightweight entity with the FiledNames returned by the SQL query (field1...field-N).
<cf:entity lightweight="true" name="myLWentity">
<cf:property name="field1" />
<cf:property name="field2" />
...
<cf:property name="fieldn" />
Then I created a CF:method with CF:body and CF:parameter sections.
<cf:method name="LoadmyLWentity" cfps:produce="false"
persistenceName="mySQLprocedure" >
<cf:body text="LOAD RAW" rawText="Select * from [dbo].ThisDoesntSeemToMatter]" language="tsql" />
<cf:parameter typeName="..." name="parameter1" />
<cf:parameter typeName="..." name="parameter2" />
...
<cf:parameter typeName="..." name="parametern" />
</cf:method>
</cf:entity>
One thing to note: The raw text ("Select * from ...") procedure name seems to be ignored so it can be anything. Instead it uses the CF:persistenceName which is the name of the stored procedure that was not created by the modeler (notice the cfps:produce="false").
The result from calling myLWentity.LoadmyLWentity is a list(of myLWentity) which is returned by mySQLprocedure.