Function imports for composable functions are not possible.

.net c# entity-framework


I have generated Entity CodeBlock for my database objects and choose some of my user defined scalar functions. But when i tried to double click on functions in Model.Store to import function i get this error.

Function imports cannot be created for composable functions.

How can i import my functions?

9/20/2012 12:59:53 AM

Accepted Answer

I don't know what I was seeing with the ExecuteFunction, but it wasn't working. I finally got an end-to-end solution together with help from this post and the article shown in the other responses.

Step one is to get the function into your EDMX file:

    <Function Name="ProcessReplacements" ReturnType="nvarchar(max)" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="Data">
      <Parameter Name="VersionId" Type="uniqueidentifier" Mode="In" />
      <Parameter Name="SurveyId" Type="uniqueidentifier" Mode="In" />
      <Parameter Name="Input" Type="nvarchar(max)" Mode="In" />

Step two is to setup a class in the same namespace as the EDMX file (easily done by creating class in the same directory as the EDMX file:

using System.Data.Objects.DataClasses;
namespace Same.As.Edmx
    public static class EdmFunctions
        [EdmFunction("SurveyDesignerModel.Store", "ProcessReplacements")]
        public static string ProcessReplacements(Guid VersionId, Guid SurveyId, string Input)
            throw new NotSupportedException("Direct calls are not supported.");

Step three is to write an object query pointing to the function:

    using System.Data.Objects;
    protected string ProcessReplacements(Guid versionId, Guid surveyId, string input)
        if (input == null)
            return null;

        List<ObjectParameter> parameters = new List<ObjectParameter>(3);
        parameters.Add(new ObjectParameter("VersionId", versionId));
        parameters.Add(new ObjectParameter("SurveyId", surveyId));
        parameters.Add(new ObjectParameter("Input", input));

        var output = db.CreateQuery<string>("SurveyDesignerModel.Store.ProcessReplacements(@VersionId, @SurveyId, @Input)", parameters.ToArray())

        return output;

The key for me was the CreateQuery call on the object context and syntax of the "query string". Notice the fully qualified reference to the function defined in the EDMX, that was my missing link :-)

5/23/2017 12:22:01 PM

Popular Answer

That is correct. You cannot create function import for SQL function but only for SQL Stored procedure. You can import SQL function to your storage model but you must manually create method to call the function:

public static class EdmFunctions
    [EdmFunction("TestModel.Store", "FunctionName")]
    public static string SomeName(string someParam)
        throw new NotSupportedException("This function is only for L2E query.");

Namespace in EdmFunction must be namespace of the store container (SSDL in EDMX file) and name must be the name of imported function. This method makes no sense when called in .NET code. Because of that it throws exception. It is only for queries translated to SQL = linq-to-entities.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow