2

I want make this in linq to sql

select isnull(x.COD, '1') as 'NCOD'
from table x

I have tried this.

From x In table
select NCOD = x.COD ?? '1';

I'm using LINQPad 4 and VB Expression. but LINQPAd says that I can't use ? expression (No se puede usar aquí el carácter '?' in Spanish)

Any idea?

PD: sorry for my English.

user1253414
  • 249
  • 1
  • 8
  • 17

2 Answers2

1

If your value type is string, you can use following expression:

result = from x in values select IF(String.IsNullOrEmpty(x),"No value",x);

If it is a nullable type (like int?, Double?, SomeClass?):

result = from x in values select IF(x.HasValue,x,1);

Ref:

Community
  • 1
  • 1
DarkWanderer
  • 8,739
  • 1
  • 25
  • 56
-1

Try the following query, this will be helpful to you.

var InvoiceNo = dbContext.table.where(x => (int?)x.ICOD) ?? "NCOD";

Here, ?? works only on nullable int int?

And you are a vb.net user than you should use following code, this will be help ful to you...

Dim InvoiceNo = If(dbContext.table.where(Function(x) DirectCast(x.ICOD, System.Nullable(Of Integer))), "NCOD")
Sagar Upadhyay
  • 819
  • 2
  • 11
  • 31
  • I'm not sure but It's possible that this is only for C#? It doesn`t work to me because says " can't use ? expression (No se puede usar aquí el carácter '?' in Spanish) " – user1253414 Nov 16 '12 at 14:53