我试图用一个 linq 句子来解决一些问题,我不知道是否可以这样做。我有一个名为 PRICES 的表,其中包含以下字段:
pkey: int
region: int?
product_type: int
product_size: int
price: double
desc: string
唯一键是:product_type + product_size
我想做一个返回所有行 WHERE region == 17 的查询(这是我的第一组行)并且想要添加所有 region 为空的行(这是我的第二组行)但是如果有行两组中的 product_type 和 product_size 相同,我希望最终结果中只有第一组的行。
例子:
pkey | region | product_type | product_size | price | desc
1, null, 20, 7, 2.70, salad1
2, null, 20, 3, 2.50, salad7
3, 17, 20, 7, 1.90, saladspecial
4, 17, 20, 5, 2.20, other
我想要一个返回这个的 linq 查询:
2, null, 20, 3, 2.50, salad7
3, 17, 20, 7, 1.90, saladspecial
4, 17, 20, 5, 2.20, other
(请注意,pkey 为 1 的行将被丢弃,因为 pkey 为 3 的行具有相同的 product_type 和 product_size)
var query1 = from p in PRICES where p.region == 17
select p;
var query2 = from p in PRICES where p.region is null
select p;
问题:
如何加入 query1 和 query2 以获得预期的输出?
只需 1 个查询即可完成?