RadControls version |
Q3 2009
|
.NET version |
3.5 sp1
|
Visual Studio version |
2008
|
programming language |
C#
|
browser support |
all browsers supported by RadControls
|
DESCRIPTION
Following these stems we will be able to execute Oracle Packages and return the Collection of entities representing the resulset.
I'm not going to post my whole project since I'm using and older version of the controls and the visual elements have changed since it was released to a better and more friendly interface, but the procedure to accomplish this task should be very similar.
- The first thing to do is to check if in your project you already have the StoredProcedure class, OpenAccess use this class to declare all your stored procedures.
*if thats not the case, you can take any other stored procedure, then use the OpenAccess wizard to generate its class, or
*just copy the code below and add it to your Model project:
*Another option is to create a copy of the stored procedure outside the package , generate the class for it then drop it.
- Ok now we have the base class and method to call a regular stored procedure. but we need to generate the entity that our SP will return, the easiest way is to take the select statement from your stored procedure and create a view for it in the database, then use the OpenAccess wizard to generate its class, after that you can remove that view from the database. in my case I generated the Entity called NavYieldsView then I dropped the view used to generate it.
- Change the return value of the stored procedure method to be IEnumerable<your_entity>, in my case IEnumerable<NavYieldsView>
- Add the name of the package and stored procedure you want to call to the GetSqlQuery function it will look something like this:
scope.GetSqlQuery<your_entity>("your_package.your_storedprocedure ?,?,?","your parameters");
in my case it is :
- Make sure you change the return type to OUT.CURSOR and if you are using parameters longer than 256 declare them as LONGVARCHAR. Also make sure you are casting the return value correctly with your entity.
- Then you need to pass these parameters to the ExecuteEnumerable method, with the exception of V_CURSOR that is not required, since the return resultset will be stored in a local Entity collection. that value can be null.
- return the res variable.
- Add the call to this method in the ODataContextClass as follow:
- now you are ready to call it from your client:
this is the code for my StoredProcedure class:
10. there you go , we are getting the entity List from our package with the minimum effort.
Thanks.