Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# entity
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
Posted 8-Feb-12 4:43am
Edited 8-Feb-12 6:49am
v3
Comments
BobJanova at 8-Feb-12 11:24am
   
What's the question? Does your second code sample not work?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you can use LINQ for searching in a LIST<> object
like
Search_option.Any(x => x.value == "a")
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 8 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100