EntityDataSource替换*上查询通配符% [英] EntityDataSource replace * with % wildcard on queries
问题描述
我有一个使用EntityDataSource在很多地方的申请。
I have an application that uses EntityDataSource in many places.
在EDS,我根据来自TextBox'es用户输入手动构建Where子句。
In the EDS, I manually build the Where clause based on user input from TextBox'es.
我想用户可以输入*(星号),而不是%查询数据时。
I would like the user to be able to enter "*" (asterisks) instead of "%" when querying data.
有一个简单的使用实体SQL或EDS本身做一个搜索/替换?我知道我可以真正改变文本框输入数据后,但用户看时,他的文字是从一个*为%改变了我不认为他会明白的。
Is there an easy as using Entity SQL or the EDS itself to do a search/replace? I know I could actually change the TextBox after the data is entered, but when the user sees his text was changed from an * to a % I don't think he will understand.
我已经使用T-SQL替换命令,做这样的事情的尝试:
I have tried using the T-SQL Replace command and doing something like this:
<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>
但我得到一个服务器标签格式不正确的消息。我找不到在实体SQL参考相当于替换功能....
But I get a "Server tag is not well formed" message. I can't find an equivalent "replace" function in the Entity SQL reference....
任何想法?
推荐答案
您可以处理网页提交和修改txtPartNumberQuery的内容。 EntityDataSource可以只%的工作(因为它建立ESQL查询),所以你必须执行绑定之前,*改为%在codebehind。
You can handle page postback and modify content of txtPartNumberQuery. EntityDataSource can work only with % (because it builds ESQL query) so you have to change * to % in your codebehind before you execute databinding.
这篇关于EntityDataSource替换*上查询通配符%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!