[英]Executing Stored Procedures With EF 5
I've got an Entity Framework application and a stored procedure I imported that takes one variable of type varchar
. 我有一个Entity Framework应用程序和我导入的存储过程,它接受一个
varchar
类型的变量。 I want to get the parameter from a text box control. 我想从文本框控件中获取参数。 The results of the stored procedure I want to set at the data source for a
GridView
control. 我想要在
GridView
控件的数据源中设置的存储过程的结果。 However, when I do dbContext.spMyProc(txtMyField.Text)
I can see with intellisense that the return type of dbContext.spMyProc(txtMyField.Text)
is int. 但是,当我执行
dbContext.spMyProc(txtMyField.Text)
我可以看到intellisense, dbContext.spMyProc(txtMyField.Text)
的返回类型是int。 I can only assume that it's returning the number of rows in the database. 我只能假设它返回数据库中的行数。 How can I do
dbContext.storedProc
and set that equal to an IEnumerable type that I can then set as the data source for a GridView
? 我如何做
dbContext.storedProc
并将其设置为等于IEnumerable类型,然后我可以将其设置为GridView
的数据源?
procedure is like 程序就像
select distinct
pdh.patientId
,p.Page
,p.Gender
,r.Race
from PatientDiagnosisHistory as pdh
inner join.... tables
I believe that you forgot to map the return type when you are importing the procedure. 我相信您在导入过程时忘记映射返回类型。
On "Add Function Import" screen you must set the entity return or create a new complex type using the columns returned by the procedure.... see this picture of the screen 在“添加函数导入”屏幕上,您必须设置实体返回或使用过程返回的列创建新的复杂类型....请参阅屏幕的此图片
if the procedure return an entity you can use this tutorial that explain how to do that. 如果该过程返回一个实体,您可以使用本教程解释如何执行该操作。
but if you need to create a new complex type using the columns a recommend that you look this answer for a similar question. 但如果您需要使用列创建新的复杂类型,建议您查看类似问题的答案 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.