Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
SolvedPrivate

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

Posted on 2014-09-22
5
Medium Priority
?
43 Views
Last Modified: 2016-02-16
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");
0
Comment
Question by:bojeff30
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 40337742
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.
0
 

Author Comment

by:bojeff30
ID: 40337946
it's delimited list
0
 

Author Comment

by:bojeff30
ID: 40339412
I've requested that this question be deleted for the following reason:

Did not get response I was looking for
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 40339413
Just because we don't get it on the first try doesn't mean we aren't willing to work on it.  There were multiple possibilities and so further clarification was needed.

The following should work for you in this case:

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

//split on the delimiter in names and then intersect the 2 arrays.
var newlist = Data.where(x => x.names.Split(',').Intersect(stringArray).Count() > 0);

Open in new window

0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question