const empty = []
const typeofNumber = (x) => ( typeof x === 'number' )
console.log(`an empty array will return ${empty.every(typeofNumber)} on an every, since "every" predicate fulfilled the condition`)
if(empty.length && empty.every(typeofNumber)) {
console.log('empty array length and every are truthy')
} else {
console.log('empty array length and every are falsey')
}
if(empty && empty.every(typeofNumber)) {
console.log('empty array and every are truthy')
} else {
console.log('empty array and every are falsey')
}
我试图弄清楚如何使用LINQ将其转换为C#。我是C#和LINQ的新手,无法正确启动我的子查询。你们其中一个巫师可以为我开灯吗?
更新-----------------
我想我已经得到了它的主旨,但是在查询最大启动日期时遇到了麻烦:
SELECT ra.ResidentID, ra.RoomID, r.Number, ra.StartDate, p.FacilityID
FROM(
SELECT ResidentID, MAX(StartDate) AS max_start
FROM RoomAssignments
GROUP BY ResidentID
) m
INNER JOIN RoomAssignments ra
ON ra.ResidentID = m.ResidentID
AND ra.StartDate = m.max_start
INNER JOIN Rooms r
ON r.ID = ra.RoomID
INNER JOIN Person p
ON p.ID = ra.ResidentID
inner join ComplianceStage cs
ON cs.Id = p.ComplianceStageID
ORDER BY ra.EndDate DESC
答案 0 :(得分:0)
在我的LINQ to SQL Recipe之后,如果你只是遵循SQL,那么转换非常简单。唯一棘手的部分是join
范围变量,从最大开始日期的子查询到RoomAssignments
中与字段名称匹配的新匿名对象。
var maxQuery = from mra in RoomAssignments
group mra by mra.ResidentID into mrag
select new { ResidentID = mrag.Key, MaxStart = mrag.Max(mra => mra.StartDate) };
var ans = from m in maxQuery
join ra in RoomAssignments on m equals new { ra.ResidentID, MaxStart = ra.StartDate }
join r in Rooms on ra.RoomID equals r.ID
join p in Persons on ra.ResidentID equals p.ID
join cs in ComplianceStage on p.ComplianceStageID equals cs.Id
orderby ra.EndDate descending
select new {
ra.ResidentID,
ra.RoomID,
r.Number,
ra.StartDate,
p.FacilityID
};