实体框架将不显示存储过程 [英] Entity Framework will not show stored procedures
问题描述
我整个上午都在混乱,但是找不到答案。我正在尝试使用EF来引用存储过程,但是无论如何我都无法将其显示在模型浏览器中。
I have been messing with this all morning, but I can't find the answer. I am trying to use EF to reference a stored procedures, but no matter what I try I cannot get it to show up in the model browser.
我使用了以下内容步骤,以使该过程进入模态:
I have used the following steps to try to get the procedures into the modal:
-
向实体模型添加过程
add procedure to Entity model
右键单击模型,然后选择添加新->函数导入
right click on model and choose add new --> Function Import
给它命名并选择我的过程
Give it a name and select my procedure
生成一个新的复杂集合(我也尝试过使用实体,但两者都不起作用)
generate a new complex collection (I have also tried using an entity, neither work)
单击确定
我已经完成了很多次,并且可以在函数导入文件夹中看到该函数在模型中,但是它从来没有出现在模型中,所以我无法引用它。
I have done this many times, and I can see the function in the "function Imports" folder in the model, but it never shows up in the model, so I can't reference it.
我发现我可以直接引用存储过程(无需导入)通过执行以下操作:
I find I can reference the stored procedure directly (without the import) by doing the following:
DBEntities db = new DBEntities();
var test = db.gsp_GetGroups();
但是,我无法将其转换为 IQueryable< T>
,但没有较大的解决方法。
However, I cannot convert this to IQueryable<T>
without a big workaround.
有人知道我缺少哪些步骤才能正确添加吗?
Does anybody know what steps I'm missing to get this to add properly?
谢谢
PS VS 2012,asp.net 4.0
P.S. VS 2012, asp.net 4.0
推荐答案
验证用于生成EF模型的SQL登录是否具有以下权限:
Verify that the SQL log-in you are using to generate your EF model has permission to execute the stored procs you are trying to import.
- 转到您的App.config并查找
connectionStrings
条目(通常在底部)。如果连接字符串多于1个,则所需的连接字符串就是您的上下文使用的连接字符串。
- 转到edmx文件并向下钻取以查找实体类。
- 例如,如果您拥有
MyDbModel.edmx
,那么在这之后您将拥有MyDbModel.Context.tt
,而该文件又将包含MyDbModel.Context.cs
。 - 在
MyDbModel.Context.cs
文件中从DbContext
继承的类,构造函数将调用base( name =<您的连接字符串名称>)
-
<您的连接字符串名称>
是您在app.config中要查找的那个。
- Go to your App.config and look for the
connectionStrings
entry (usually at the bottom). If you have more than 1 connection string, the one you want is the one your context uses.- Go to your edmx file and drill down to find the entities class.
- For example, if you have
MyDbModel.edmx
, then under that you'll haveMyDbModel.Context.tt
which in turn will containMyDbModel.Context.cs
. - In the
MyDbModel.Context.cs
file you will have a class that inherits fromDbContext
and the constructor will callbase("name=<your connection string name>")
<your connection string name>
is the one you are looking for in your app.config.
这篇关于实体框架将不显示存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!