Page 1 of 1

Using oracle functions

Posted: Tue 12 Apr 2011 11:53
by Jupiler
I'm trying to understand how a simple oracle function (returning a string) can be used with the entity framework 4. I'm using the devart entity developer to create my edmx.
I'm only able to get this working when adding an output parameter in the entity method and setting the value by using the command text (ie: begin :result := mySchema.testfunction(); end;)
and then calling the function in visual studio with the output parameter:
ObjectParameter param = new ObjectParameter("result", "");
myObjectcontext.ExecuteFunction("Testfunction", param);
MessageBox.Show(param.Value.ToString());

But this seems to be a bit stupid, I would like to use the function like this:
ObjectResult result = myObjectcontext.ExecuteFunction("Testfunction");

My question is how to setup the entitymethod for this to work, I've set the return type to string and mapped to the oracle function but this results in a "PLS-00306: wrong number or types of arguments in call to 'TESTFUNCTION" error message.
Can anyone help or is there some documentation on the subject?
Many thanks

Posted: Wed 13 Apr 2011 08:32
by AndreyR
Please perform the following steps:
1. Drag the Testfunction function on the designer surface.
2. Go to the Moder Explorer->Model.Store. Edit the properties of this function: set Concealed to true.
3. Drag the function from the Model.Store to the designer surface.
4. Change the Return Type of the generated method (Model Explorer->Methods->Testfunction->Properties) to String.

Posted: Wed 13 Apr 2011 08:52
by Jupiler
Thank you for you reply, I’ve amended the properties like you explained. When I try to execute the code I get an error: EntityCommandExecutionException: The data reader returned by the store data provider does not have enough columns for the query requested.
I’m calling the function using:
ObjectResult result = EFContext.ExecuteFunction("Testfunction");
It seems like the result of the database function is not passed to the result of the generated method.

Posted: Wed 13 Apr 2011 09:04
by AndreyR
Call the function like in the following snippet:

Code: Select all

string s = myObjectcontext.Testfunction();

Posted: Wed 13 Apr 2011 09:11
by Jupiler
Hi Audry,
The function is not available in my objectcontext, I cannot see it on the edml/x either but it does exist as a method.
Any idea why?
Thanks

Posted: Wed 13 Apr 2011 11:33
by AndreyR
Are you using the default code generation?
Please send us the model or a small test project reproducing the issue.

Posted: Wed 13 Apr 2011 11:44
by Jupiler
No, I've set the code generation strategy to none and am using the ADO.NET C# POCO Entity Generator template. When setting it to default the function is available. Is there any way to use the template and still have the functions available on my objectcontext?

Posted: Wed 13 Apr 2011 12:02
by Jupiler
I've managed to get the functions available on my objectcontext but am still running into the same error:
"The data reader returned by the store data provider does not have enough columns for the query requested."
I'm sending you my edml by mail, maybe you are able to see what's wrong.

Posted: Wed 13 Apr 2011 13:24
by AndreyR
Take a look at the POCO template discussion.
It contains links to some corrections associated with the Stored Procedures.

Posted: Wed 13 Apr 2011 13:33
by Jupiler
The function is in my context now but I'm still getting the "The data reader returned by the store data provider does not have enough columns for the query requested." error, this is not a T4 template problem is it?

Posted: Thu 14 Apr 2011 13:26
by AndreyR
I have made a simple test using a very simple function (it just returned 'test') and succeeded using the latest 6.10.135 build of dotConnect for Oracle.
Could you please upgrade to the latest build?
Please let me know if the error persists.

Posted: Mon 18 Apr 2011 08:34
by Jupiler
Hi Andrey,
I've upgraded to the latest version and I'm now able to get the result like this:
ObjectResult result = myObjectcontext.Testfunction();
Your example with:
string s = myObjectcontext.Testfunction();
is not working, is there a property that I should change?
Regards,
Femke

Posted: Mon 18 Apr 2011 09:13
by AndreyR
Maybe your procedure returns a set of strings instead of single strings.
The code you are using is correct as well.

Posted: Mon 18 Apr 2011 09:21
by Jupiler
My function is only returning a single string:
CREATE OR REPLACE FUNCTION JIT.testfunction
RETURN VARCHAR2
IS
BEGIN
RETURN 'Test function = OK!!';
END;
/
How can I 'tell' the entity developer that it is returning a single string?
These are my settings:
Aggregate False
Built In False
Command Test
Composable False
Concealed Function True
Name TESTFUNCTION
Niladic False
Parameter Type Semantics AllowImplicitConversion
Result Set Parameter Name
Return Type VARCHAR2
Schema JIT
Store Procedure Name

Posted: Mon 18 Apr 2011 10:38
by AndreyR
Go to the Model Explorer->Model->Methods->Testfunction, open the Properties window, and set the Return Type to string. It should help.