asp.net - EntityDataSource 在查询中用 % 通配符替换 *

标签 asp.net entity-framework-4

我有一个在很多地方使用 EntityDataSource 的应用程序。

在 EDS 中,我根据来自 TextBox 的用户输入手动构建 Where 子句。

我希望用户在查询数据时能够输入“*”(星号)而不是“%”。

有没有像使用 Entity SQL 或 EDS 本身那样简单的搜索/替换?我知道我实际上可以在输入数据后更改 TextBox,但是当用户看到他的文本从 * 更改为 % 时,我认为他不会理解。

我尝试过使用 T-SQL Replace 命令并执行如下操作:

<asp:EntityDataSource ID="EDSParts" runat="server" 
    ConnectionString="name=TTEntities" DefaultContainerName="TTEntities"
    EnableFlattening="False" EntitySetName="Parts"
    OrderBy="it.ID DESC"
    Where ="(CASE
                WHEN (@PartNumber IS NOT NULL) THEN
                    it.[Number] LIKE REPLACE(@PartNumber, "*", "%")
                ELSE
                    it.[ID] IS NOT NULL
            END)">
    <WhereParameters>
        <asp:ControlParameter Name="PartNumber" Type="String"
            ControlID="txtPartNumberQuery" PropertyName="Text" />
    </WhereParameters>
</asp:EntityDataSource>

但我收到“服务器标记格式不正确”的消息。我在 Entity SQL 引用中找不到等效的“替换”函数....

有什么想法吗?

最佳答案

您可以处理页面回发和修改 txtPartNumberQuery 的内容。 EntityDataSource 只能与 % 一起使用(因为它构建 ESQL 查询),因此您必须在执行数据绑定(bind)之前在代码隐藏中将 * 更改为 %。

关于asp.net - EntityDataSource 在查询中用 % 通配符替换 *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4632512/

相关文章:

jquery - 使用输入类型按钮在 asp.net 中进行验证

c# - Xamarin 表单设置 Picker SelectedItem

asp.net - 如何解决asp网站初始加载速度慢的问题?

c# - 添加引用asp.net后编译错误

c# - 理解 Entity Framework 下的多表结果

c# - 是否可以让 ASP.NET Core 解决方案包含具有不同目标框架的项目?

.net - Entity Framework 4.3 遇到的最大池大小

c# - 在 .net 4 中获取连接字符串

c# - Entity Framework 4.1 - 如何将 "Force"EF 转至 DB 而不是使用 Graph?

asp.net-mvc-2 - ASP.net MVC 2 应用程序教程,使用带有许多表的 Entity Framework