Error calling Stored Procedures from EntityFramework

42,848

Solution 1

You may want to refer to this blog post: FunctionImport is not mapped to a store function Error, that discusses a similar problem. The cause apparently being:

I had to make changes to a stored procedure and it got deleted from the Entity Data Model Xml file (*.edmx)

With the following step-by-step solution:

There is an easy solution to fix that error. First open your edmx file and right click on the model that owns the stored procedure. Click Add then select “Add Function Import”.

Add the same Function Import name that is used in your Context file (if like me, the method was already created but messed up, otherwise is all new and it will be recreared anyways). Select the Stored Procedure Name that you are trying to fix. Choose the Entities and click OK. A new window might pop up “Verify that the FunctionImport name is unique”.

If that is the case, and you get the “Verify that the FunctionImport name is unique” window popup, do the following: Open your *.edmx file and right click over the model you want to update. Select “Show in Model Browser”. Now the Model Browser window opens up. Go to: {myProject}.DataModel > EntityContainer: {somethingEntities} > Function Imports. The function import causing the problem should be there, just delete it and save the *.edmx file.

Try to add the Function Import again. Voila! no issues this time. Save the *.edmx file and recreate the context file (by making a simple non-invasive change like adding a space to the {myProject}.Context.tt file). make sure the new method:

public virtual ObjectResult<MyEntity> <MyEntity>_NameoftheSP(parametets) is present in your Context file.

Another troubleshooting resource with similar step-by-step instructions (and images!) on updating the edmx file: The function import cannot be executed because it is not mapped to a store function.

Solution 2

This post should be a comment but I don't have enough rep to comment.

I was having a similar issue. My stored procedures were visible and yet I was still getting the error. This question and answer from Alex led me to look under Function Imports in the Model Browser and I saw that I had multiple entries for each of the stored procedures. They had sequence numbers to prevent them from being true duplicates. I removed everything under Function Imports and everything under Stored Procedures / Functions and then re-added them by updating the model from the database. My issue is now resolved.

Solution 3

When you open the edmx explorer (Diagram Mode), you will see the model explorer window on the side of you diagram.

On the Function Import Section try to find your stored function. Right click on it, then you can modify it.

A Window will be opened, then choose your stored function. a function will mapped after That

Voila, it works for me.

Solution 4

I had this error:

The function import *XXX* cannot be executed because it is not mapped to a store function.

when I check, my stored procedure was deleted from database. I created it again, and it fixed the error.

Solution 5

For those of you who tried the solution, but still does not work, make sure your proc don't have any issues with invalid columns names, or any other related issues. I got the same error message, but in my case it was an invalid column name reference in the proc.

Share:
42,848
Ingrid
Author by

Ingrid

Updated on April 07, 2021

Comments

  • Ingrid
    Ingrid about 3 years

    I am trying to access a Store Procedure from EntityFramework.

    I have followed these steps:

    First of all I have created the Stored Procedure in the Azure Database:

    enter image description here

    Then, I have updated the .edmx model from database, selecting only the StoredProcedure I want.

    enter image description here

    Once done, in the Function Import I see the StoredProcedure added, but not in the section of StoredProcedures. What can I do so that it appears here?

    enter image description here

    In the Function Import section, all the parameters are set as Input, whereas "MaxReference" should be marked as Output. How can I change it?

    enter image description here

    Although these two issues I have executed the code:

    enter image description here

    and I got the following exception:

    EntityCommandCompilationException
    An error occurred while preparing command definition. See the inner exception for details.
    

    and the InnerException:

    The function import 'DataModelEntities.AssignMaxSalesRef' cannot be executed because it is not assigned to a storage function.
    

    enter image description here