我想寫下面的左外部在Linq中加入scenerio到實體的語法,我不能爲我的生活弄清楚如何將它拉下來... 這裏是工作SQL,我想最終達到:LINQ到實體 - 唯一的左外部加入Scenerio
SELECT *
學生小號 LEFT JOIN ParentStudents PS開ps.StudentId = s.StudentId AND ps.ParentId =「6D279F72-2623-459F -B701-5C77C52BA52F'
其中s.TenantId = 3 AND s.FamilyId ='28833312-46eb -4a54-9132-8a7c8037cec5'
以粗體突出顯示的部分是我跌倒的地方...我希望學生無論數據庫中是否存在ParentStudent記錄都會返回。
這是我最新的LINQ到實體代碼不起作用:
public ICollection<ParentStudentListing> GetParentStudents(Guid FamilyId, Guid ParentId)
{
var query = from s in DataContext.Students
from ps in s.ParentStudents.DefaultIfEmpty()
where s.TenantId == CurrentUser.TenantId && s.FamilyId == FamilyId && ps.ParentId == ParentId
select new ParentStudentListing { StudentId = s.StudentId, FirstName = s.FirstName, MiddleName = s.MiddleName, LastName = s.LastName, RelationshipId = ps.RelationshipId, ParentStudentId = ps.ParentStudentId, isAllowedToPickUp = ps.isAllowedToPickUp, isEmergency = ps.isEmergency, isLiveIn = ps.isLiveIn, ParentId = ps.ParentId };
return query.ToList();
}
此代碼不帶回來的學生除非有這不是想要的結果數據庫ParentStudent記錄。無論是否有ParentStudent記錄,我都希望帶回學生,但如果有ParentStudent記錄,我希望那些與學生記錄結合起來...
謝謝!
喬你回答同樣有幫助!再次感謝! –