我是Entity框架的新手,在使用EF和Linq查询方面不是很专业。我有3个表Condition Group
,Condition
和TenantCondition
表。加入条件和Condition Group
表工作完美,但在条件租户表的加入条件我面临的问题。以下是我的查询。
var qry = (from ConditionGroups in db.ConditionGroups.Include("Conditions")
where ConditionGroups.IsActive == true
select new ConditionGroupsEntity
{
ConditionGroupGUID = ConditionGroups.ConditionGroupGUID,
ConditionName = ConditionGroups.ConditionGroupName,
ConditionList = (from condition in ConditionGroups.Conditions
join tenantCondition in db.TenantConditions on condition.ConditionID
equals tenantCondition.ConditionID
where condition.ConditionTypeID == (int)Enums.ConditionTypes.Allergen
&& (condition.TenantID == null || tenantCondition.TenantID == (usr != null ? usr.TenantID : null)
&& condition.IsPublic == true)
select new ConditionListEntity
{
ConditionGUID = condition.ConditionGUID,
ConditionName = condition.ConditionName
}).ToList()
});
return qry.ToList();
请建议如何解决此问题。