我想写下面的左外部在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记录,我希望那些与学生记录结合起来...
谢谢!
乔你回答同样有帮助!再次感谢! –