Tables => 组 子群
我需要从Groups表中选择仅通过(复选框)检查的组包含SubgroupId
下面的语句有效,但它也会选择具有空子组的组。请帮忙
var test =
this.MailingGroupRepository.List().ToList()
.Cast<MailingGroup>()
.Select(e => new campaignSegmentCondition
{
extra = string.Empty,
field = "interests-" + e.GroupingId,
op = "all",
value = string.Join(",",
updateRow.MailingSubgroup
.Where(r => r.MailingGroupId == e.MailingGroupId)
.Select(p => p.Name))
}).ToList<campaignSegmentCondition>();
答案 0 :(得分:1)
如果我理解这个问题,那么有一个非常简单的解决方案。试试这个:
var test =
this.MailingGroupRepository.List().ToList()
.Cast<MailingGroup>()
.Where(e => updateRow.MailingSubgroup
.Any(r => r.MailingGroupId == e.MailingGroupId))
.Select(e => new campaignSegmentCondition
{
extra = string.Empty,
field = "interests-" + e.GroupingId,
op = "all",
value = string.Join(",",
updateRow.MailingSubgroup
.Where(r => r.MailingGroupId == e.MailingGroupId)
.Select(p => p.Name))
}).ToList<campaignSegmentCondition>();
请注意包含以下代码:
.Where(e => updateRow.MailingSubgroup
.Any(r => r.MailingGroupId == e.MailingGroupId))
答案 1 :(得分:0)
您可以在where where子句中检查邮件子组是否为空? -
updateRow.MailingSubgroup
.Where(r => !r.IsEmpty && r.MailingGroupId == e.MailingGroupId)
如果没有IsEmpty
属性,您还可以检查r.Items.Count > 0
之类的内容。