CONVERT A LIST TO A STRING LIST

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
C# 
C#
 1242  View(s)
Ratings:
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>'

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Convert a list to a string list

    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();

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!