Link to home
Start Free TrialLog in
Avatar of bojeff30
bojeff30

asked on

use LINQ in C# to filter a return database list using values from a string array.

I would like to  use LINQ in C# to filter a return database list using values from a string array. How can i get the list of rows out of my database list, where the rows have matching values in my String Array?


example:
string[] stringArray = { "Bob", "Joe", "Dan", "Rick" };

var newlist = Data.where(x => x.names.Contains("any names from my string Array");
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

if name is a single value you can do this:
string[] stringArray = { "Bob", "Joe", "Dan", "Rick" };

string searchString = ",";

foreach (string s in stringArray)
 searchString += s + ",");

//searchstring= ",Bob,Joe,Dan,Rick,"

 Data.where(x => searchString.Contains("," + x.Name + ",");

Open in new window


If Names is a delimited list itself that gets a little more complicated.  Let me know.
Avatar of bojeff30
bojeff30

ASKER

it's delimited list
I've requested that this question be deleted for the following reason:

Did not get response I was looking for
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial