我可以从EntityDataSource调用存储过程吗

我可以从EntityDataSource调用存储过程吗

本文介绍了我可以从EntityDataSource调用存储过程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

(ASP.net 3.5,C#,SQL Express 2008)

(ASP.net 3.5, C#, SQL Express 2008)

我想要一个Web表单,可以在其中搜索解决方案(我的表格)使用用户输入的关键字,然后返回结果并填充GridView。

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.

我已经通过连接到实体数据模型的存储过程进行了部分搜索。在此页面上,我有一个EntityDataSource。 如何使该EntityDataSource从存储过程中获取数据?

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?

我意识到我可以通过Entity上下文获取结果(有效) ),并将其绑定到网格,但是如果我不将其连接到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)

推荐答案

尝试使用函数导入


  1. 右键单击EntitySet名称(标题部分)

  2. 选择添加->函数导入

这是一篇不错的博客文章,供您查看。

Here is a good blog post for you to check out. ADO.NET Entity Framework Tools: Stored Procedures, by Guy Burstein

更新:抱歉,我错过了有关 EntityDataSource ,所以我不知道可以访问从EDS导入函数的任何属性,但是您可以尝试使用CommandText属性。

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.

<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>

更新:看来我有一些坏消息。使用深入研究 EntityDataSource EntityDataSourceView 使用 QueryBuilderUtils.ConstructQuery 构造,然后依次调用 context.CreateQuery< T> 。执行函数导入所需的是对 context.ExecuteFunction< T> 的调用。在此版本中似乎没有对ExecuteFunction的任何支持,我正在阅读的博客确实提到它是计划好的,但无论它是否在将来的版本中,它都没有加入该版本中。

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.

话虽如此,我建议使用 ObjectDataSource ,您可以通过以下方式构造它:仍然支持分页,排序等。如果您打开与此主题有关的ObjectDataSource问题,请在此处给我发送评论,我看一下。

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.

这篇关于我可以从EntityDataSource调用存储过程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 03:07