let slotObj = {};
let slotId = 'slot1' // hardcoded for SO but this is populated via a parent for loop so would be slot2, slot3 etc
slotObj[slotId] = {};
for (let i = 0; i < assetList.length; i++) {
let assetItem = assetList[i];
slotObj[slotId]['slotContent'+i] =
{ // <-- how to make this unique using iterator ie. slotContent0, slotContent1 etc...
'templateNo': assetItem.dataset.template,
'assetId': assetItem.dataset.contentId
}
}
from p in context.ParentTable
join c in context.ChildTable on p.ParentId equals c.ChildParentId into j1
from j2 in j1.DefaultIfEmpty()
group j2 by p.ParentId into grouped
select new { ParentId = grouped.Key, Count = grouped.Count(t=>t.ChildId != null) }
(from p in context.ParentTable
join c in context.ChildTable
on p.ParentId equals c.ChildParentId into j1
from j2 in j1.DefaultIfEmpty()
select new {
ParentId = p.ParentId,
ChildId = j2==null? 0 : 1
})
.GroupBy(o=>o.ParentId)
.Select(o=>new { ParentId = o.key, Count = o.Sum(p=>p.ChildId) })
Рассмотрите возможность использования подзапроса:
from p in context.ParentTable
let cCount =
(
from c in context.ChildTable
where p.ParentId == c.ChildParentId
select c
).Count()
select new { ParentId = p.Key, Count = cCount } ;
Если типы запросов связаны ассоциацией, это упрощается до:
from p in context.ParentTable
let cCount = p.Children.Count()
select new { ParentId = p.Key, Count = cCount } ;