private static void BuildJoinCondition(SqlQuery query, SqlQueryJoin join, QueryConditionDef condition, DocDef docDef, SqlQueryCondition parentCondition, IDataContext dataContext) { if (condition.Condition != ConditionOperation.Include && condition.Condition != ConditionOperation.Exp) { var leftPart = BuildConditionPart(query, condition.Left, dataContext); var rightPart = BuildConditionPart(query, condition.Right, dataContext); join.Conditions.Add(new SqlQueryCondition(condition.Operation, leftPart, condition.Condition, rightPart)); } else if (condition.Condition == ConditionOperation.Include && condition.Conditions != null && condition.Conditions.Count > 0) { var attrDef = String.IsNullOrEmpty(condition.AttributeName) ? docDef.Attributes.First(a => a.Id == condition.AttributeId) : docDef.Attributes.First( a => String.Equals(a.Name, condition.AttributeName, StringComparison.OrdinalIgnoreCase)); query.JoinSource(query.FindSourceByDocDef(docDef), attrDef.DocDefType.Id, SqlSourceJoinType.Inner, attrDef.Id); foreach (var child in condition.Conditions) { BuildJoinCondition(query, join, child, attrDef.DocDefType.Id, parentCondition, dataContext); } } else if (condition.Condition == ConditionOperation.Exp && condition.Conditions != null) { var exp = new SqlQueryCondition(null, condition.Operation, Guid.Empty, ConditionOperation.Exp, null); foreach (var child in condition.Conditions) { BuildJoinCondition(query, join, child, docDef, exp, dataContext); } } }
private static void BuildJoinCondition(SqlQuery query, SqlQueryJoin join, QueryConditionDef condition, Guid docDefId, SqlQueryCondition parentCondition, IDataContext dataContext) { // using (var defRepo = new DocDefRepository(dataContext)) var defRepo = query.Provider.Get <IDocDefRepository>(); { var docDef = defRepo.DocDefById(docDefId); BuildJoinCondition(query, join, condition, docDef, parentCondition, dataContext); } }
public int TryGetAttributeIndex(SqlQueryJoin join, Guid attrDefId) { var attr = Query.Attributes.FirstOrDefault(a => a.Source == join.Source && a.Def != null && a.Def.Id == attrDefId); if (attr == null) { return(-1); } return(Query.Attributes.IndexOf(attr)); }
private static void BuildJoin(SqlQuery query, QueryJoinDef join, DocDef docDef, IDataContext dataContext) { var source = query.Sources.First( s => String.Equals(s.AliasName, join.Source.Alias, StringComparison.OrdinalIgnoreCase)); var queryJoin = new SqlQueryJoin(source, join.Operation); foreach (var condition in join.Conditions) { BuildJoinCondition(query, queryJoin, condition, docDef, null, dataContext); } query.SourceJoins.Add(queryJoin); }