2015-05-13 8 views
17

Ich versuche, eine Store-Prozedur von EntityFramework zugreifen.Fehler beim Aufrufen von Stored Procedures von EntityFramework

ich diese Schritte befolgt haben:

Als erstes habe ich die gespeicherte Prozedur in der Azure-Datenbank erstellt haben:

enter image description here

Dann habe ich die .edmx Modell aus der Datenbank aktualisiert, die Auswahl nur die StoredProcedure, die ich möchte.

enter image description here

Einmal in der Funktion Import getan, sehe ich die StoredProcedure hinzugefügt, aber nicht in dem Abschnitt von StoredProcedures. Was kann ich tun, damit es hier erscheint?

enter image description here

im Funktions Import Abschnitt werden alle Parameter werden als Eingabe gesetzt, während „MaxReference“ als Ausgabe markiert werden soll. Wie kann ich es ändern?

enter image description here

Obwohl diese beiden Fragen ich den Code ausgeführt haben:

enter image description here

und ich bekam die folgende Ausnahme:

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

und die Innerexception:

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

enter image description here

Antwort

18

Sie können zu diesem Blog-Post beziehen möchten: FunctionImport is not mapped to a store function Error, die ein ähnliches Problem diskutiert. Die Ursache offenbar sein:

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

Mit der folgenden Schritt-für-Schritt-Lösung:

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.

Eine weitere Problem Ressource mit ähnlichen Schritt-für-Schritt-Anweisungen (und Bildern!) Auf die edmx Datei aktualisieren : The function import cannot be executed because it is not mapped to a store function.

+0

Mein Problem ist, dass bei der Auswahl "Funktion Import hinzufügen" habe ich keine Optionen für die Stored Procedure/Function Name. – Ingrid

18

Dieser Beitrag sollte ein Kommentar sein, aber ich habe nicht genug Rep zu kommentieren.

Ich hatte ein ähnliches Problem. Meine gespeicherten Prozeduren waren sichtbar und trotzdem bekam ich den Fehler. Diese Frage und Antwort von Alex führte mich dazu, unter Funktionsimporte im Modellbrowser nachzusehen, und ich sah, dass ich für jedes der gespeicherten Prozeduren mehrere Einträge hatte. Sie hatten Sequenznummern, um zu verhindern, dass sie echte Duplikate waren. Ich habe alles unter Function Imports und alles unter Stored Procedures/Functions entfernt und dann neu hinzugefügt, indem ich das Modell aus der Datenbank aktualisiert habe. Mein Problem wurde behoben.

+0

gre8 ... hat gut funktioniert :) –

+2

Das hat bei mir funktioniert. Ich musste auch das p_procname_Result-Objekt im Ordner "Complex Types" im Modellbrowser entfernen. –

1

Ich hatte diesen Fehler:

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

wenn ich überprüfen, wurde meine gespeicherte Prozedur aus der Datenbank gelöscht. Ich habe es erneut erstellt und den Fehler behoben.

0

Wenn Sie den edmx explorer (Diagrma-Modus) öffnen, sehen Sie das Modell-Explorer-Fenster an der Seite Ihres Diagramms.

Auf Funktion Import Sektion versuchen, Tour gespeicherte Funktion zu finden, Rechtsklick darauf, dann können Sie es ändern.

Ein Fenster wird geöffnet, wählen Sie dann Ihre gespeicherte Funktion. eine Funktion mapsed nach diesem

voila, es funktioniert für mich.

Verwandte Themen