Page 1 of 1

Use NVL in LINQ

Posted: Wed 28 Sep 2011 09:14
by Citt_jr
Hello,

How to use the Oracle function NVL in LINQ ?

Exemple :
SELECT *
FROM TABLE
WHERE Field = NVL(1020, UID)

LINQ
query.Where(t => t.Field == ??????);

Thanks

Citt_jr

Posted: Thu 29 Sep 2011 16:23
by StanislavK
No .NET methods are translated into the NVL Oracle function. However, you can get the same result by using the null-coalescing operator ('??' in C#):

Code: Select all

query.Where(t => t.Field == UID ?? 1020);
Please tell us if this helps.

Posted: Mon 03 Oct 2011 07:02
by Citt_jr
Hello,

I need this feature to improve the query plan because you do not manage HINTS

Posted: Tue 04 Oct 2011 13:41
by StanislavK
We will consider implementing the translation of the null-coalescing operator to the NVL function. However, we cannot provide any timeframe for this feature.

At the moment, you can use this function or hints manually via the ExecuteQuery generic method:

Code: Select all

var query = dataContext.ExecuteQuery(
  "select field1, field2, ... from myTable where field1 = NVL(...)"
);
or add text WHERE conditions via the Dynamic Query library:

Code: Select all

query = query.Where("field1 = NVL(...)");