When using Linq, there's no use or point in using SqlDataReader....
You really didn't show much to go on - but basically, with Linq, you should have a DbContext (that's your "connection" to the database), and that DbContext should contain any number of DbSet - basically representing the tables in your database. You select from these DbSet's and then you get back a List<Entity> which you just iterate over.
Something along the lines of:
-- select your customers matching a certain criteria
var customers = NorthwindDbContext.Customers.Where(x => x.statementYear == response[i]).ToList();
-- iterate over your customers
foreach (Customer c in customers)
{
// do whatever with your "Customer" here
}
UPDATE:
from your updated question - all you really need is:
List<string> paths = new List<string>();
using (var db = new FMBDBPRDEntities1())
{
List<ClientStatement_Inventory> years = new List<ClientStatement_Inventory>();
years = years.Where(x => x.statementYear == response[i]).ToList();
foreach (var year in years)
{
paths.Add(year.statementPath);
}
}
That opens the context to access the database, reads some data into a list, iterates over the elements in the list - done. Everything else is useless and can be just deleted.
And you could write this a lot simpler, too:
using (var db = new FMBDBPRDEntities1())
{
List<string> paths = years.Where(x => x.statementYear == response[i])
.Select(y => y.statementPath).ToList();
}
UPDATE #2: if your response is a collection of values (I'm assuming those would be int values), and you need to iterate over it - try something like this:
if (response != null)
{
List<string> allPaths = new List<string>();
using (var db = new FMBDBPRDEntities1())
{
foreach (int aYear in response)
{
List<string> paths = years.Where(x => x.statementYear == aYear)
.Select(y => y.statementPath).ToList();
allPaths.AddRange(paths);
}
}
return allPaths; // or do whatever with your total results
}
UPDATE #3: just wondering - it seems you never really access the DbContext at all ..... I'm just guessing here - but something along the lines of:
if (response != null)
{
List<string> allPaths = new List<string>();
using (var db = new FMBDBPRDEntities1())
{
foreach (int aYear in response)
{
// access a DbSet from your DbContext here!
// To actually fetch data from the database.....
List<string> paths = db.ClientStatement_Inventory
.Where(x => x.statementYear == aYear)
.Select(y => y.statementPath).ToList();
allPaths.AddRange(paths);
}
}
return allPaths; // or do whatever with your total results
}