Ejemplo n.º 1
0
        public bool IsSame(Guid id, QuerySourceDef source)
        {
            var single = Def as QuerySingleAttributeDef;

            return(single != null && single.Attribute != null && single.Attribute.AttributeId == id &&
                   single.Attribute.Source != source);
        }
Ejemplo n.º 2
0
        public QueryJoinDef AddJoin(QuerySourceDef source, SqlSourceJoinType joinType)
        {
            Def.Sources.Add(source);
            if (!String.IsNullOrWhiteSpace(source.Alias))
            {
                _sourceAliases.Add(source.Alias, source);
            }
            else
            {
                _sourceAliasNo++;
                while (_sourceAliases.ContainsKey("source" + _sourceAliasNo))
                {
                    _sourceAliasNo++;
                }

                source.Alias = "source" + _sourceAliasNo;
                _sourceAliases.Add(source.Alias, source);
            }
            var join = new QueryJoinDef {
                Source = source, Operation = joinType
            };

            Def.Joins.Add(join);
            return(join);
        }
Ejemplo n.º 3
0
        public override bool IsSame(QuerySourceDef sourceDef)
        {
            if (sourceDef == null)
            {
                return(false);
            }

            if (sourceDef.SubQuery == null)
            {
                return(false);
            }

            if (String.Equals(sourceDef.Alias, AliasName))
            {
                return(true);
            }

            // TODO: Доделать сравнение, чтобы точно возвращать соответствие
            if (sourceDef.SubQuery.Source.DocDefId == SubQuery.Def.Id)
            {
                return(true);
            }

            /*return docDef != null && ((sourceDef.DocDefId != Guid.Empty && docDef.Id == sourceDef.DocDefId) ||
             *                        String.CompareOrdinal(docDef.Name, sourceDef.DocDefName) == 0 &&
             *                        !String.IsNullOrEmpty(sourceDef.DocDefName));
             */
            return(false);
        }
Ejemplo n.º 4
0
 public QueryAttributeDef FindAttribute(string attrName, QuerySourceDef source)
 {
     if (Def.Attributes != null)
     {
         return
             (Def.Attributes.FirstOrDefault(a => new QueryAttributeDefHelper(a).IsSame(attrName, source)));
     }
     return(null);
 }
Ejemplo n.º 5
0
        public bool IsSame(string attrName, QuerySourceDef source)
        {
            var single = Def as QuerySingleAttributeDef;

            return(single != null && single.Attribute != null &&
                   (String.Equals(single.Attribute.AttributeName, attrName, StringComparison.OrdinalIgnoreCase) ||
                    String.Equals(single.Alias, attrName, StringComparison.OrdinalIgnoreCase)) &&
                   single.Attribute.Source == source);
        }
Ejemplo n.º 6
0
 public static QueryAttributeDef Create(Guid id, string alias, QuerySourceDef source)
 {
     return(new QuerySingleAttributeDef
     {
         Alias = alias,
         Attribute = new QueryAttributeRef {
             AttributeId = id, Source = source
         }
     });
 }
Ejemplo n.º 7
0
 public static QueryAttributeDef Create(string name, string alias, QuerySourceDef source)
 {
     return(new QuerySingleAttributeDef
     {
         Alias = alias,
         Attribute = new QueryAttributeRef {
             AttributeName = name, Source = source
         }
     });
 }
Ejemplo n.º 8
0
        public IQueryJoin RightJoin(QueryDef query, string alias)
        {
            var helper = new QueryDefHelper(Def);
            var source = new QuerySourceDef {
                Alias = alias, SubQuery = query
            };
            var join = helper.AddJoin(source, SqlSourceJoinType.RightOuter);

            return(new QueryJoinBuilder(this, join));
        }
Ejemplo n.º 9
0
        public QueryAttributeDef AddAttribute(Guid id, QuerySourceDef source)
        {
            var attr = FindAttribute(id);

            if (attr == null)
            {
                var alias = GetUniqueAttributeAlias(DefaultAlias);
                attr = QueryAttributeDefHelper.Create(id, alias, source);
                Def.Attributes.Add(attr);
            }
            return(attr);
        }
Ejemplo n.º 10
0
        public QueryAttributeDef AddAttribute(string attrName, QuerySourceDef source)
        {
            var attr = FindAttribute(attrName, source);

            if (attr == null)
            {
                var alias = GetUniqueAttributeAlias(attrName);
                attr = QueryAttributeDefHelper.Create(attrName, alias, source);
                Def.Attributes.Add(attr);
            }
            return(attr);
        }
Ejemplo n.º 11
0
        public virtual bool IsSame(QuerySourceDef sourceDef)
        {
            if (sourceDef == null)
            {
                return(false);
            }

            var docDef = GetDocDef();

            return(docDef != null && ((sourceDef.DocDefId != Guid.Empty && docDef.Id == sourceDef.DocDefId) ||
                                      String.CompareOrdinal(docDef.Name, sourceDef.DocDefName) == 0 &&
                                      !String.IsNullOrEmpty(sourceDef.DocDefName)));
        }
Ejemplo n.º 12
0
 private static void BuildSource(SqlQuery query, QuerySourceDef source, IDocDefRepository defRepo, IDataContext dataContext)
 {
     if (source.SubQuery != null)
     {
         var subQuery = Build(dataContext, source.SubQuery);
         query.Sources.Add(new SqlQuerySubSource(subQuery, source.Alias));
     }
     else if (source.DocDefId != Guid.Empty)
     {
         query.Sources.Add(new SqlQueryDocSource(query.Provider, source.DocDefId, source.Alias));
     }
     else if (!String.IsNullOrEmpty(source.DocDefName))
     {
         var sourceDocDef = defRepo.DocDefByName(source.DocDefName);
         query.Sources.Add(new SqlQueryDocSource(query.Provider, sourceDocDef, source.Alias));
     }
 }
Ejemplo n.º 13
0
        public IQuery Join(QueryDef query, string alias, Action <IQueryExpression> conditionAction)
        {
            var source = new QuerySourceDef
            {
                SubQuery = query,
                Alias    = alias
            };
            var joinDef = new QueryJoinDef
            {
                Operation = SqlSourceJoinType.Inner,
                Source    = source
            };

            Def.Sources.Add(source);
            var expBuilder = new QueryJoinBuilder(this, joinDef);

            Def.Joins.Add(joinDef);
            conditionAction.Invoke(expBuilder);
            return(this);
        }
Ejemplo n.º 14
0
        public IQuery FullJoin(string docDefName, string alias, Action <IQueryExpression> conditionAction)
        {
            var source = new QuerySourceDef
            {
                DocDefName = docDefName,
                Alias      = alias
            };

            Def.Sources.Add(source);
            var joinDef = new QueryJoinDef
            {
                Operation = SqlSourceJoinType.FullOuter,
                Source    = source
            };

            var expBuilder = new QueryJoinBuilder(this, joinDef);

            Def.Joins.Add(joinDef);
            conditionAction.Invoke(expBuilder);
            return(this);
        }
Ejemplo n.º 15
0
        public IQuery Join(Guid docDefId, string alias, Action <IQueryExpression> conditionAction)
        {
            var source = new QuerySourceDef
            {
                DocDefId = docDefId,
                Alias    = alias
            };
            var joinDef = new QueryJoinDef
            {
                Operation = SqlSourceJoinType.Inner,
                Source    = source/*,
                                   * Conditions = expBuilder.Conditions*/
            };

            Def.Sources.Add(source);

            var expBuilder = new QueryJoinBuilder(this, joinDef);

            Def.Joins.Add(joinDef);
            conditionAction.Invoke(expBuilder);
            return(this);
        }
Ejemplo n.º 16
0
 public QuerySourceDefHelper(QuerySourceDef def)
 {
     Def = def;
 }