我想使用LINQ to SQL根据数组中的值查询相应的数据,但遇到问题。我读这些线程,但我不知道他们是否实际上是我想要做的,如果他们是如何实现它们:如何为数组中的每个条目运行查询?
LINQ equivalent of foreach for IEnumerable<T>
我有我的数组字符串的行[]',我怎样才能为每个条目运行以下查询,并以一种允许我以一致的方式输出它们的方式存储结果。 再次这里是我的数组的一个示例: 例子: 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);
}
列表创建是好的,我也想在写列表将是确定的,但我不能弄清楚如何为每个物品运行查询int array?
我的数组中的每个条目都以Z开头,然后包含字母数字字符的任何排列(如果它很重要)。示例:Z3333
数组中的每个条目都对应于数据库'SpecificTable'中表中的条目。我想在该表中返回与此值相关的所有内容,以便我可以输出该数据的详细信息。
例子: 我想quering Z1234开始,当Z1234在“SpecificTable”发现我希望能够输出各种细节是这样的:
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());
}
通过使用循环希望能够根据初始数组创建所有结果的列表,并输出其相应的各种值,如'说明'。
如果这还不够信息,请让我知道我可以提供更清楚。
'foreach(var result in thisQuery){results.Add(result); }'可缩短为'results = thisQuery.ToList();' – nothrow