Rahul Parab
Rahul Parab

Reputation: 27

Get values from a column having comma separated values using Linq

I am working in a web based application in which i am using lots of Linq query to fetch the data. I am stuck in one issue were in i need to get the rows from a column which has a comma separated values in it. I have a screen shot below :

Table

As you can see that in the above screen shot we have 5 columns. I need data such that in the network column. For eg: Network column first row has CMT, second row also has CMT and other rows also has CMT respectively. But in the 8th row there is no CMT. I need the rows only from networks having CMT values in it. Can anybody help me to write a Linq query?

Upvotes: 0

Views: 1123

Answers (1)

JohnyL
JohnyL

Reputation: 7132

This should help:

var list = new List<dynamic>
{
    new {userid="SIMONE", networks = "CMT,MTT,MVV"},
    new {userid="CURTINK", networks = "MTR,NAN,NOG"},
    new {userid="JAMESL", networks = "CMT,LOGO,CMDY"},
    new {userid="BONDINEG", networks = "TVL,TVLC,NKTN"}
};
var users = String.Join(",", list.Where(d => d.networks.Contains("CMT"))
                                 .Select(u => u.userid));

Upvotes: 2

Related Questions