0

This is my SQL query:

select 
   S.student_No, 
   coalesce(P.Name,'0'),
   P.Surname 
from 
   Person as P 
join 
   Student as S 
       on P.Id = S.Person_Id

I want to convert it LINQ , i did it except coalesce function,

from P in cbu.PERSON
join S in cbu.STUDENT on P.ID equals S.PERSON_ID
select new
{
     S.Stundent_No,
     P.Name,
     P.Surname,
};

how can I use coalesce in this linq query

Cœur
  • 37,241
  • 25
  • 195
  • 267
Taha Karaca
  • 111
  • 1
  • 1
  • 10

1 Answers1

0

P.Name ?? "0". C# has the coalesce operator built-in. Even if you didn't know that, you could use the ?: operator.

The join is not necessary, btw. You can just write P.Student.Stundent_No (or whatever the properties are called).

usr
  • 168,620
  • 35
  • 240
  • 369