2015-05-13 17 views
17

Sto tentando di accedere a una procedura di archiviazione da EntityFramework.Errore nel chiamare le stored procedure da EntityFramework

Ho seguito questi passi:

Prima di tutto ho creato la stored procedure nel database Azure:

enter image description here

Poi, ho aggiornato il modello edmx dal database, selezionando solo lo StoredProcedure che voglio.

enter image description here

Una volta fatto, nella importazione Funzione vedo lo StoredProcedure aggiunto, ma non nella sezione di StoredProcedures. Cosa posso fare in modo che appaia qui?

enter image description here

Nella sezione Importa funzione, tutti i parametri sono impostati come input, mentre "MaxReference" deve essere contrassegnato come uscita. Come posso cambiarlo?

enter image description here

Sebbene queste due questioni che ho eseguito il codice:

enter image description here

ed ho ottenuto la seguente eccezione:

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

e l'InnerException:

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

enter image description here

risposta

18

Si consiglia di fare riferimento a questo post del blog: FunctionImport is not mapped to a store function Error, che discute un problema simile. La causa sembra essere:

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

con la seguente soluzione step-by-step:

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.

Un'altra risorsa di risoluzione dei problemi con simili istruzioni passo-passo (e le immagini!) Su come aggiornare il file edmx : The function import cannot be executed because it is not mapped to a store function.

+0

Il mio problema è che quando si seleziona "Aggiungi funzione di importazione" non ho nessuna opzione sul nome della stored procedure/funzione. – Ingrid

18

Questo post dovrebbe essere un commento ma non ho abbastanza rep per commentare.

Stavo riscontrando un problema simile. Le mie stored procedure erano visibili e tuttavia ricevevo ancora l'errore. Questa domanda e risposta di Alex mi ha portato a consultare le importazioni di funzioni nel browser del modello e ho visto che avevo più voci per ognuna delle stored procedure. Avevano numeri di sequenza per impedire che fossero veri duplicati. Ho rimosso tutto sotto Function Import e tutto sotto Stored Procedures/Functions e poi li ho riaggiunti aggiornando il modello dal database. Il mio problema è ora risolto.

+0

gre8 ... ha funzionato bene :) –

+2

Questo ha funzionato per me. Ho anche dovuto rimuovere l'oggetto p_procname_Result nella cartella Tipi complessi nel browser del modello. –

1

ho avuto questo errore:

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

quando controllo, la mia stored procedure è stata eliminata dal database. L'ho creato di nuovo e ha corretto l'errore.

0

Quando si apre edmx explorer (modalità Diagrma), verrà visualizzata la finestra di esplorazione del modello sul lato del diagramma.

Nella sezione di importazione delle funzioni, cercare di trovare la funzione di giro memorizzata, fare clic con il tasto destro su di essa, quindi modificarla.

Si aprirà una finestra, quindi scegliere la funzione memorizzata. una funzione verrà mappata dopo quella

voilà, funziona per me.

Problemi correlati