Home > DeveloperSection > Forums > Convert a list to a string list
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    March-29-2014 3:26 AM

 C# C# 
Ratings:


 1 Reply(s)
 847  View(s)
Rate this:

var listID = from Ines in ineContext.IneDetailRecords

             select Ines.InePIN.ToString().ToList();

string PIN = something;

if(!listID.Contains(PIN))

    // save it to DB

InePIN is a cloumn in SQL Server DB, the type is varchar(20).

The exception is:

Instance argument: cannot convert from 'System.Linq.IQueryable<System.Collections.Generic.List<char>>' to 'System.Linq.ParallelQuery<string>'



Pravesh Singh

Total Post:411

Points:2881
Posted on    March-29-2014 6:59 AM

Hi Ankita,

You need to apply the ToList method on result of query but not on the selected column i.e Ines.InePIN.ToString().ToList()

Change

var listID = from Ines in ineContext.IneDetailRecords

                                       select Ines.InePIN.ToString().ToList();

To

var listID = (from Ines in ineContext.IneDetailRecords

                                       select Ines.InePIN.ToString()).ToList();


Don't want to miss updates? Please click the below button!

Follow MindStick