在实体框架中条件所在的位置使用列表 [英] Use list in where condition in entity framework
本文介绍了在实体框架中条件所在的位置使用列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在实体框架中包含我的搜索值的线索中使用列表.
How can I use list in where clues in Entity Framework that list contain my searching value.
List<String> Search_option= new List<string>();
Search_option.add("a");
Search_option.add("b");
var Data= from a in Db_table select a;
而且我也使用此代码:
And I also use this code too:
var Data= from a in Db_table where(Search_option.contains(a.Field.Tostring())) select a;
谢谢
Thanks
推荐答案
,您可以使用LINQ在LIST<>中进行搜索.对象
喜欢
Search_option.Any(x => x. value =="a")
you can use LINQ for searching in a LIST<> object
like
Search_option.Any(x => x.value == "a")
我建议您可以对参数使用DropdownList
在线标记
-----------
I Suggest you can use DropdownList for your Parameters
markup in line
-----------
<asp:dropdownlist id="ddlSearchOption" runat="server">
<asp:listitem text="-- Select One --" value="" selected="True"></asp:listitem>
<asp:listitem text="A" value="A"></asp:listitem>
<asp:listitem text="B" value="B"></asp:listitem>
</asp:dropdownlist>
背后的代码
-----------
Code Behind
-----------
var Data = from a in Db_table
where a.fieldName == this.ddlSearchOption.SelectedValue
select a;
Other Option
var Data = Db_table.Where(a => a.fieldName.Contains(this.ddlSearchOption.SelectedValue).ToList();
希望对您有帮助
别忘了投票
谢谢
Hope this will help you
don''t forget to vote
thanks
这篇关于在实体框架中条件所在的位置使用列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文