(ASP.net 3.5, C#, SQL Express 2008)
(ASP.net 3.5,C#,SQL Express 2008)
I want to have a Web Form, where I can search for "Solutions" (my table) using a keyword entered by the user and after the result comes back and populates a GridView.
我想要一个Web表单,我可以使用用户输入的关键字搜索“解决方案”(我的表),然后结果返回并填充GridView。
I already have parts of this search via a stored procedure that is hooked up to my Entity Data Model. On this page I have an EntityDataSource. How can I make this EntityDataSource grab data from my stored procedure?
我已经通过连接到我的实体数据模型的存储过程获得了此搜索的一部分。在这个页面上我有一个EntityDataSource。如何使此EntityDataSource从我的存储过程中获取数据?
I realize I could just fetch the result via the Entity context (which works), and bind it to the grid, but if I don't hook it up to the EntityDataSource I won't get automatic paging and sorting (which has been another struggle of mine in the past)
我意识到我可以通过Entity上下文(它工作)获取结果,并将其绑定到网格,但如果我不将它连接到EntityDataSource,我将不会得到自动分页和排序(这是另一个我过去的斗争)
1 个解决方案
#1
Try using the Function Import
.
尝试使用“函数导入”。
- Right click on the EntitySet Name (the heading part)
- Choose Add->Function Import
右键单击EntitySet名称(标题部分)
选择Add-> Function Import
Here is a good blog post for you to check out. ADO.NET Entity Framework Tools: Stored Procedures, by Guy Burstein
这是一篇很好的博客文章,供您查看。 ADO.NET实体框架工具:存储过程,作者:Guy Burstein
Update: Sorry I missed the part about the EntityDataSource
so I don't know of any property exposed to access a function import from the EDS, but your can try to use the CommandText property.
更新:对不起,我错过了关于EntityDataSource的部分,所以我不知道有任何属性暴露从EDS访问函数导入,但您可以尝试使用CommandText属性。
<asp:EntityDataSource ID="SolutionsDataSource" runat="server"
CommandText="DataModel.SearchFunction(@Keywords)"
ConnectionString="name=AdventureWorksEntities">
<CommandParameters>
<asp:ControlParameter Name="Keywords"
ControlID="SearchTextbox" Type="String"/>
</CommandParameters>
</asp:EntityDataSource>
Update: Well it seems that I have some bad news. After using Reflector to dive deep into the EntityDataSource
. The EntityDataSourceView
is constructed using QueryBuilderUtils.ConstructQuery
, which then in turn calls context.CreateQuery<T>
. What you would need to execute the function import is a call to context.ExecuteFunction<T>
. There doesn't seem to be any support for the ExecuteFunction in this release, the blogs I was reading did mention that it was planned, but it didn't make it into this release, whether or not it will be in future releases I can't say.
更新:似乎我有一些坏消息。使用Reflector深入潜入EntityDataSource之后。 EntityDataSourceView使用QueryBuilderUtils.ConstructQuery构造,然后依次调用context.CreateQuery
That being said I would recommend using an ObjectDataSource
, which you can construct in a way that still supports paging, sorting, etc. If you open an ObjectDataSource question on this topic send me a comment here and I'll take a look.
话虽这么说我会建议使用一个ObjectDataSource,你可以用一种仍然支持分页,排序等方式构建它。如果你打开一个关于这个主题的ObjectDataSource问题,请在这里给我发表评论,我会看看。
#1
Try using the Function Import
.
尝试使用“函数导入”。
- Right click on the EntitySet Name (the heading part)
- Choose Add->Function Import
右键单击EntitySet名称(标题部分)
选择Add-> Function Import
Here is a good blog post for you to check out. ADO.NET Entity Framework Tools: Stored Procedures, by Guy Burstein
这是一篇很好的博客文章,供您查看。 ADO.NET实体框架工具:存储过程,作者:Guy Burstein
Update: Sorry I missed the part about the EntityDataSource
so I don't know of any property exposed to access a function import from the EDS, but your can try to use the CommandText property.
更新:对不起,我错过了关于EntityDataSource的部分,所以我不知道有任何属性暴露从EDS访问函数导入,但您可以尝试使用CommandText属性。
<asp:EntityDataSource ID="SolutionsDataSource" runat="server"
CommandText="DataModel.SearchFunction(@Keywords)"
ConnectionString="name=AdventureWorksEntities">
<CommandParameters>
<asp:ControlParameter Name="Keywords"
ControlID="SearchTextbox" Type="String"/>
</CommandParameters>
</asp:EntityDataSource>
Update: Well it seems that I have some bad news. After using Reflector to dive deep into the EntityDataSource
. The EntityDataSourceView
is constructed using QueryBuilderUtils.ConstructQuery
, which then in turn calls context.CreateQuery<T>
. What you would need to execute the function import is a call to context.ExecuteFunction<T>
. There doesn't seem to be any support for the ExecuteFunction in this release, the blogs I was reading did mention that it was planned, but it didn't make it into this release, whether or not it will be in future releases I can't say.
更新:似乎我有一些坏消息。使用Reflector深入潜入EntityDataSource之后。 EntityDataSourceView使用QueryBuilderUtils.ConstructQuery构造,然后依次调用context.CreateQuery
That being said I would recommend using an ObjectDataSource
, which you can construct in a way that still supports paging, sorting, etc. If you open an ObjectDataSource question on this topic send me a comment here and I'll take a look.
话虽这么说我会建议使用一个ObjectDataSource,你可以用一种仍然支持分页,排序等方式构建它。如果你打开一个关于这个主题的ObjectDataSource问题,请在这里给我发表评论,我会看看。