2015-05-13 34 views
17

Tôi đang cố gắng truy cập Quy trình lưu trữ từ EntityFramework.Lỗi khi gọi Thủ tục lưu sẵn từ EntityFramework

Tôi đã theo các bước sau:

Trước hết tôi đã tạo ra các Stored Procedure trong cơ sở dữ liệu Azure:

enter image description here

Sau đó, tôi đã cập nhật mô hình .edmx từ cơ sở dữ liệu, lựa chọn chỉ có StoredProcedure mà tôi muốn.

enter image description here

Sau khi thực hiện, trong nhập Function tôi thấy StoredProcedure thêm, nhưng không phải trong phần StoredProcedures. Tôi có thể làm gì để nó xuất hiện ở đây?

enter image description here

Trong phần nhập khẩu Chức năng, tất cả các tham số được thiết lập như là đầu vào, trong khi "MaxReference" nên được đánh dấu là Output. Làm cách nào để thay đổi?

enter image description here

Mặc dù hai vấn đề này tôi đã thực hiện các mã:

enter image description here

và tôi đã nhận ngoại lệ sau đây:

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

và InnerException:

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

enter image description here

Trả lời

18

Bạn có thể muốn tham khảo bài viết trên blog này: FunctionImport is not mapped to a store function Error, thảo luận về một vấn đề tương tự. Nguyên nhân rõ ràng là:

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

Với bước-by-step giải pháp sau đây:

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.

Một nguồn lực xử lý sự cố với bước theo bước hướng dẫn tương tự (và hình ảnh!) Về việc cập nhật các tập tin edmx : The function import cannot be executed because it is not mapped to a store function.

+0

Vấn đề của tôi là khi chọn "Thêm chức năng nhập" tôi không có tùy chọn nào trên Thủ tục lưu trữ/Tên hàm. – Ingrid

18

Bài đăng này phải là nhận xét nhưng tôi không có đủ đại diện để nhận xét.

Tôi gặp sự cố tương tự. Các thủ tục đã lưu trữ của tôi đã hiển thị và tôi vẫn gặp lỗi. Câu hỏi và câu trả lời này từ Alex đã dẫn tôi đến xem trong Nhập khẩu chức năng trong Trình duyệt mô hình và tôi thấy rằng tôi có nhiều mục nhập cho mỗi thủ tục được lưu trữ. Họ có các số thứ tự để ngăn chúng không bị trùng lặp. Tôi đã xóa mọi thứ trong Nhập khẩu chức năng và mọi thứ trong Thủ tục/Chức năng được lưu trữ và sau đó thêm lại chúng bằng cách cập nhật mô hình từ cơ sở dữ liệu. Vấn đề của tôi hiện đã được giải quyết.

+0

gre8 ... đã hoạt động tốt :) –

+2

Điều này phù hợp với tôi. Tôi cũng phải loại bỏ đối tượng p_procname_Result trong thư mục Complex Types trong trình duyệt mô hình. –

1

Tôi có lỗi này:

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

khi tôi kiểm tra, thủ tục lưu trữ của tôi đã bị xóa khỏi cơ sở dữ liệu. Tôi tạo lại nó và sửa lỗi.

0

Khi bạn mở trình thám hiểm edmx (Chế độ Diagrma), Bạn sẽ thấy cửa sổ trình khám phá mô hình ở bên cạnh bạn Sơ đồ.

Trên mục nhập chức năng cố gắng tìm chuyến tham quan Chức năng được lưu trữ, nhấp chuột phải vào nó, sau đó bạn có thể sửa đổi nó.

Cửa sổ sẽ mở ra, sau đó chọn chức năng được lưu trữ của bạn. một chức năng sẽ được lập bản đồ sau đó

thì đấy, nó phù hợp với tôi.

Các vấn đề liên quan