1

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:

  • We are using EntityFramework 6.X (.NET Framework 4.6) with a Database-first logic
  • We would not update the websites EDMX
  • We would not use only SQL queries (there is, unfortunately, no way to mix Linq-to-Entities and RawSQL queries)
  • We would not execute the request before applying filters and clauses (for performance reasons)

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.

Sackey
  • 392
  • 2
  • 11

0 Answers0