Sackey
Sackey

Reputation: 402

How to use a Database-first registered DbFunction inside another context with Linq To Entities?

I would provide an Oracle Database function (ie. RemoveDiacritics) in my low-layer C# package which is installed on multiple websites, to allow these applications to use my custom function inside their Linq To Entities queries. The goal is to provide a way to use this function as simple as possible with no need to update their own EDMX models.

In order to provide this function to other applications, I have created an empty EDMX model, then I have added the RemoveDiacritics function in the store:

<Function Name="REMOVEDIACRITICS" Aggregate="false" BuiltIn="true" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="MP" ReturnType="varchar2">
    <Parameter Name="INPUT" Type="varchar2" Mode="In" />
</Function>

I also expose the following function extension:

public static class DbTools
{
    [DbFunction("ModelDbFunction.Store", "REMOVEDIACRITICS")]
    public static string RemoveDiacritics(this string input)
    {
        throw new NotSupportedException("this function is not supported");
    }
}

But I'm a bit lost: how to mix my DbFunction context with other website context to allow them to use this function? Is there an other approach (based on Database-first logic) to provide a database function, according to the following restrictions:

EDIT: Another approach would be to find a way to bind dynamically a DbFunction on a context in the C# package side, making the RemoveDiacritics function usable inside the Linq query; but this doesn't seem really possible, as I didn't found any alternative to do this (still with database-first).

Thanks for your help.

Upvotes: 1

Views: 249

Answers (0)

Related Questions