Reputation: 117
I have two tables:
tab1 tab2
ID | Name | Sername | PostID ID | PostDecription
The question: how can I show in tab1 in cell PostID cell from tab2 PostDecription if PostDecription could has value NULL?
(from p in tab1 join s in tab2 on p.PostID equals
s.ID select new
{
ID = p.ID,
Name= p.Name,
Sername = p.Sername,
PostID = s.PostDecription,
})
Using this code I can get only cells that have the same value in two tables. What about case when PostDecription could has value "NULL"???
Upvotes: 1
Views: 102
Reputation: 15673
You need a left join
from p in tab1
join s in tab2 on p.PostID equals s.ID into tab2s
from s in tab2s.DefaultIfEmpty()
select new
{
ID = p.ID,
Name= p.Name,
Sername = p.Sername,
PostID = s.PostDecription,
}
Upvotes: 2