【发布时间】:2018-11-23 06:58:10
【问题描述】:
我有多个记录的 linq 查询,我正在使用 where 子句过滤这些记录。
现在,如果过滤后的记录没有返回任何内容,那么我需要将其设为默认值,以从列表中获取默认的任何单个记录。
var resultStaffGua = (from s in _db.Students
join sg in _db.StudentStaffGuardians on s.StudentID equals sg.StudentId
join g in _db.Staffs on sg.StaffId equals g.StaffID
join lr in _db.luRelationTypes on sg.RelationTypeId equals lr.RelationTypeID
join ga in _db.StaffAddresses on g.StaffID equals ga.StaffID
join ad in _db.Addresses on ga.AddressID equals ad.AddressID
where
lse.StatusID == (int?)Extension.StatusType.Active
&& lse.TenantID == tenantid
select new
{
g.FirstName,
g.LastName,
IsPrimary = sg.IsPrimaryGuardian,
se.Email,
Phone = sphon.PhoneNumber,
lr.RelationCD,
gdnr.GenderCD,
ad.Zipcode
}).Where(i=>i.IsPrimary==true);
如果resultStaffGua 计数0,我需要来自resultStaffGua 的一条记录。谢谢
【问题讨论】:
-
什么
result?什么parentList?除此之外我不明白这个问题 -
@MickyD - 查看我的更新问题。
-
@CGPA6.4,您尝试过 JohnWu 的以下回答吗?
-
@er-shoaib -John 的回答看起来直截了当。我本来可以想到的。我愿意做单行。谢谢。
标签: c# .net linq linq-to-entities