0

I have a list<abbreviatedProducts> that I need to cross-reference with values from my sql server 2008 database.

I am imagining I have to iterate the string and hit the database each time for each product.

List<string> abbreviatedProducts = new[] { strawb, bana, ki, orang };

for each (var item in products)
{
  //hit database to get full product name;
}

Is this the best way?

4

1 回答 1

1

有一种更快的方法,你可以这样做:

List<string> products = new [] { "prod1", "prod2", "prod3" };

var dbProducts = datacontext.Products.Where(pr => products.Contains(pr.ProductName));

这假设您的Products表中有一个名为ProductName“prod1”等名称的列。

于 2012-09-10T16:01:53.970 回答