Equivalent for sqlserver isnull(E.Empid,'') in Linq
How to check the nulls
in linq please help me
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Mar 25, 2011, 12:29 PM
VulpesPosted Mar 25, 2011, 10:46 AM
I tend to overlook this unless I'm working with nullable types but you're right - it can be used with reference types such as string too.
VulpesPosted Mar 25, 2011, 9:54 AM
Suthish NairPosted Mar 25, 2011, 9:23 AM
Raja KrishnamurthyPosted Mar 25, 2011, 8:02 AM
var query = from emp in context.Employee
select new{
EmployeeId = emp.EmpId ?? "", //think use of ?? is better in case of checking null than use of ?
EmployeeName = emp.FirstName + " " + emp.LastName
};
HTH.
Happy Programming!!!
Regards,
Raja
VulpesPosted Mar 25, 2011, 7:29 AM
let temp = (E.Empid == null) ? "" : E.Empid
and then use 'temp' in the rest of the query
Suthish NairPosted Mar 25, 2011, 7:25 AM