I am trying to use LINQ to SQL to query corresponding data based on the values in my array, but am having issues. I was reading these threads, but am not sure if they are actually what I'm trying to do, and if they are how to implement them:
LINQ equivalent of foreach for IEnumerable<T>
I have my Array of strings 'lines[]', how can I run the following query for each entry, and store the results in a way that allows me to output them in a coherent manner. Again here is a sample of my array: Example: Z1234 Z2345 ZAF38383
//some non working code
List<string> results = new List<string>();
var thisQuery = from c in myContext.SpecificTable
where c.itemNumber == (foreach (string i in lines))
select c;
foreach (var result in thisQuery)
{
results.Add(result);
}
The list creation is fine, and the write to the list would be ok too I think, but I can't figure out how to run the query for each item int he Array?
Each entry in my array begins with Z and then will contain any arrangement of alpha-numeric characters if it matters. Example: Z3333
Each entry in the array corresponds to an entry in a table in my database 'SpecificTable'. I want to return everything pertaining to this value, in that table, so I can then output the specifics of that data.
Example: I want to begin by quering Z1234, and when Z1234 is found in 'SpecificTable' I want to be able to output the various details like this:
foreach (var res in thisQuery)
{
//each result from the query (total of 3 from the example) will now show their Description in a messagebox.
MessageBox.Show("Description:" + res.Description.ToString());
}
By using the loop I hope to be able to create a list of all results based on the initial array, and output their corresponding various values such as the 'Description'.
If this is still not enough info, please let me know what I can provide to be more clear.