VB linq to sql isnull
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.
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:
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")
链接地址: http://www.djcxy.com/p/42858.html
上一篇: 三元或不三元?
下一篇: VB LINQ到SQL isnull