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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Suthish NairRank #92 · 22.8K reputationPosted Mar 25, 2011, 3:25 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 25, 2011, 3:29 AM EDT
let temp = (E.Empid == null) ? "" : E.Empid
and then use 'temp' in the rest of the query
Raja KrishnamurthyRank #3,615 · 403 reputationPosted Mar 25, 2011, 4:02 AM EDT
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
Suthish NairRank #92 · 22.8K reputationPosted Mar 25, 2011, 5:23 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 25, 2011, 5:54 AM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 25, 2011, 6:46 AM EDT
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.
Suthish NairRank #92 · 22.8K reputationPosted Mar 25, 2011, 8:29 AM EDT