I'm working on an application which accesses data from an Oracle 11g database. I'm using EF4 and data is accessed using LINQ. I have come across a scenario where I need to call a function stored in a package. This function also has a return value. I have added this function to the entity data model but am unable to perform "Add Function Import" on it. Hence I'm unable to access it using LINQ. How can I call this function and also get it's return value?
I asked this question a while back, but have not got any answer for it yet. Anyways, I'm updating it with some details so that it becomes convenient for others to understand the issue and guide me in the right direction. I have tried to implement the solution proposed in this question, but am getting an exception.
I've added the following to the designer.cs file of my entity data model:
[EdmFunction("TestModel.Store", "TestFunction")]
public int TestFunction(decimal ALNR, decimal ATID, decimal AUKENR)
{
throw new ApplicationException();
}
Following is a small portion of the edmx file:
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="TestModel.Store" Alias="Self" Provider="Oracle.DataAccess.Client" ProviderManifestToken="11g" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
<Function Name="TestFunction" ReturnType="number" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" StoreFunctionName="PKG_TURNUS.SUMUKE" Schema="SYSTEM">
<Parameter Name="ATID" Type="number" Mode="In" />
<Parameter Name="ALNR" Type="number" Mode="In" />
<Parameter Name="AUKENR" Type="number" Mode="In" />
</Function>
Here is how I am calling this function:
var selectQuery = from T in _context.Table1
join A in _context.Table2 on T.columnA equals A.columnB
join TU in _context.Table3 on T.columnC equals TU.columnD
where T.columnD == 5 && T.columnE == someVariable
select new someType
{
propertyA = A.columnG,
propertyB = _context.TestFunction(T.columnE, A.columnF, TU.columnH)
};
But when I do any of the following:
ObservableCollection<someType> weekTotaldata = new ObservableCollection<someType>(selectQuery); //Exception thrown at runtime
or
foreach (var ttu in selectQuery) //Exception thrown at runtime
{
double testval = ttu.propertyB;
}
I get the exception that is thrown in that function "ApplicationException". Shouldn't this exception be thrown when this function is called anywhere else exception the L2E query?
What am I doing wrong? How can I call an oracle function from Linq-To-Entities? Please note that the function that I am trying to call is not a built-in oracle function, but a user-defined function.