所有記錄我有2個表:Linq to SQL |獲取其中一個外鍵不存在
Schools
-------
pk_school_id,
title
和
Business_Hours
--------------
pk_id,
fk_school_id
我想pk_school_id和標題從學校表不存在由於fk_school_id所有pk_school_id在Business_Hours表中。
var Schools = (from b in Db.Language_School_Business_Hours
join s in Db.Language_Schools on b.fk_school_id equals s.pk_school_id into lrs
from lr in lrs.DefaultIfEmpty()
select new
{
LeftID = b.fk_school_id,
RightId = ((b.fk_school_id == lr.pk_school_id) ? lr.pk_school_id : 0)
});
感謝您的編輯Andy! – vohrahul