我的Linq语句出错了。 现在问题是我在一个使用自定义构建数据层的项目,所以我不知道我是在创建错误的Linq语句还是数据层无法处理它。
所以这是声明:
IQueryable<Affiliate> temp;
Func<RolePersonRole, bool> func;
if (roleMustBePrimary)
{
func = role => role.RolePersonRoleIsPrimary.Value == true;
}
else
{
func = role => role.RoleId == role.RoleId;
}
temp = (from affiliate in DataFacade.Instance().Tables(SessionTicket).Affiliates()
join role in DataFacade.Instance().Tables(SessionTicket).RolePersonRoles().Where(func) on affiliate.PersonId
equals role.PersonId
where role.RoleId == roleId
&& affiliate.AffiliateAssuranceLevel == assuranceLevelEnum
select affiliate);
意思是如果bool roleMustBePrimary
为真,则应添加where语句,如果为false,则不应添加(因此role => role.RoleId == role.RoleId
)。
我得到的错误是:
表达式 'System.Collections.Generic.IEnumerable`1 [SkillsNG.Modules.RolePersons.Entities.RolePersonRole]' 不是序列
答案 0 :(得分:2)
正如Wouter所说,你不需要.Where()
,你可以更清楚地表达它:
var temp =
from affiliate in DataFacade.Instance().Tables(SessionTicket).Affiliates()
join role in
from r in DataFacade.Instance().Tables(SessionTicket).RolePersonRoles()
where roleMustBePrimary && r.RolePersonRoleIsPrimary.Value
|| !roleMustBePrimary
select r
on affiliate.PersonId equals role.PersonId
where role.RoleId == roleId
&& affiliate.AffiliateAssuranceLevel == assuranceLevelEnum
select affiliate;