1 つの linq 文だけで何かを解決しようとしていますが、これが可能かどうかはわかりません。次のフィールドを持つ PRICES という名前のテーブルが 1 つあります。
pkey: int
region: int?
product_type: int
product_size: int
price: double
desc: string
一意のキーは次のとおりです: product_type + product_size
すべての行を返すクエリを実行したい WHERE region == 17 (これは私の最初の行セットです) AND region が null であるすべての行を追加したい (これは私の 2 番目の行セットです) しかし、両方のセットで同じ 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 3 の行は product_type と product_size が同じであるため、pkey 1 の行は破棄されることに注意してください)
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つのクエリだけで実行できますか?