Function imports for composable functions are not possible.

.net c# entity-framework


For my database objects, I built Entity CodeBlocks and selected a few of my user-defined scalar methods. However, I see this issue when I attempt to double-click on a function in Model.Store to import it.

Composable functions cannot have import statements generated for them.

I want to import my functions, but how?

9/20/2012 12:59:53 AM

Accepted Answer

What I was seeing with the ExecuteFunction wasn't functioning, for some reason. With assistance from this post and the article mentioned in the other comments, I was able to come up with a whole solution in the end.

Adding the function to your EDMX file is the first step.

    <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" />

Creating a class in the same directory as the EDMX file makes it simple to build a class in the same namespace as the EDMX file in step two.

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.");

The third step is to create an object query that references 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 CreateQuery call on the object context and "query string" syntax was crucial for me. That was my missing piece; note the fully qualified reference to the function described in the EDMX.

5/23/2017 12:22:01 PM

Popular Answer

That is accurate. Function imports can only be created for SQL Stored Procedures; you cannot make them for SQL Function. The SQL function may be imported into your storage model, however the way to invoke the function must be explicitly created:

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

in namespaceEdmFunction name must be the name of the imported function, and must be the namespace of the storage container (SSDL in EDMX file). When invoked from.NET code, this function makes no sense. This causes it to throw an exception. It only applies to SQL queries that are 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