basically i have some data table similar to this

```
| ItemId | RuleId | IsActive |
------------------------------
| ItemA  | RuleA  | FALSE    |
------------------------------
| NULL   | RuleA  | TRUE     |
------------------------------
| ItemC  | RuleA  | TRUE     |
------------------------------
| ItemA  | RuleB  | FALSE    |
------------------------------
| NULL   | RuleB  | TRUE     |
------------------------------

```

and i want to get result like this

for item a

```
| ItemId | RuleId | IsActive |
------------------------------
| ItemA  | RuleA  | FALSE    |
------------------------------
| ItemA  | RuleB  | FALSE    |
------------------------------

```

for item b

```
| ItemId | RuleId | IsActive |
------------------------------
| NULL   | RuleA  | TRUE     |
------------------------------
| NULL   | RuleB  | TRUE     |
------------------------------

```

for item c

```
| ItemId | RuleId | IsActive |
------------------------------
| ItemC  | RuleA  | TRUE     |
------------------------------
| NULL   | RuleB  | TRUE     |
------------------------------

```

basically if there's specific rule, then use the specified, otherwise use the default rule setting with null as itemId

how to achieve this in linq?

Thanks in advance

EDIT: thanks for styling, @lazyberezovsky. @dasblinkenlight I don't have the query for sql either. I do need in linq way, but it's also of great help if anyone can give me some advice how to get the result in sql way.