1

我有一个PromotionRequest有 4 列的表:

| PromoId | PromoType 
----------------------
|   101   |  1   |  
|   101   | 2    |  
|   103   | 3    |  
|   104   | 4    |  

我有一个PromotionResponsek有 4 列(PromoId, PromoType, Value, PromoDesc)的表,其中之一是PromoId

我必须找到其值与表PromotionResponsePromoId值匹配的所有行。PromoIdPromotionRequest

4

3 回答 3

5

你已经用 SQL 标记了这个,所以如果你想在 SQL 中执行这个,那么你将使用INNER JOIN

select rs.promoid,
  rs.promotype,
  rs.value,
  rs.promodesc
from PromotionResponse rs
inner join PromotionRequest pr
  on rs.promoid = pr.promoid
于 2013-01-18T11:42:08.447 回答
4

您可以尝试这种 linq 方式在响应表中查找 id,如下所示

List<int> ids = requesttable.AsEnumerable()
               .Select(r => (int) r["Id"])
               .ToList();


var query = from item in responsetable.AsEnumerable()
            where ids.Contains( (int) item["Id"] )
            select item;
于 2013-01-18T11:42:12.867 回答
0
var matched = from table1 in PromotionRequest.AsEnumerable()
               join table2 in PromotionResponse .AsEnumerable() on
               table1.Field<string>("PromoId ") equals table2.Field<string>("PromoId ")
               where table1.Field<string>("PromoId ") == table2.Field<string>("PromoId ")
               select table2;
if (matched.Any())
 {
 }
于 2013-01-18T12:03:58.763 回答