Beispiel #1
0
        private void CreateClauses(List <Tuple <string, List <SqlParameter> > > whereClauses, HashSet <string> innerJoins, List <IOrderByClause> orderByClauses, List <IEntitySearch <Car> > search, List <IEntityOrderBy <Car> > order)
        {
            if (search != null)
            {
                foreach (var item in search)
                {
                    var res  = WhereFactory.CreateWhereClause(item);
                    var join = res.GenerateJoin();
                    if (!string.IsNullOrEmpty(join))
                    {
                        innerJoins.Add(join);
                    }

                    whereClauses.Add(res.GenerateWhereClause());
                }
            }

            if (order != null)
            {
                foreach (var item in order)
                {
                    var res  = OrderByFactory.CreateOrderByClause(item);
                    var join = res.GenerateInnerJoin();
                    orderByClauses.Add(res);
                    if (!string.IsNullOrEmpty(join))
                    {
                        innerJoins.Add(join);
                    }
                }
            }
        }
        private void ApplyWhere(StringBuilder builder, List <IEntitySearch <T> > search, SqlCommand command, List <IEntityOrderBy <T> > order)
        {
            var whereClauses = new List <Tuple <string, List <SqlParameter> > >();
            var innerJoins   = new HashSet <string>();

            if (search != null)
            {
                foreach (var item in search)
                {
                    var res  = WhereFactory.CreateWhereClause(item);
                    var join = res.GenerateJoin();
                    innerJoins.Add(join);
                    whereClauses.Add(res.GenerateWhereClause());
                }
            }

            if (order != null)
            {
                foreach (var item in order)
                {
                    var res  = OrderByFactory.CreateOrderByClause(item);
                    var join = res.GenerateInnerJoin();
                    innerJoins.Add(join);
                }
            }

            foreach (var item in innerJoins)
            {
                builder.Append(item);
            }

            if (whereClauses.Count > 0)
            {
                builder.Append(" WHERE ");
                for (int i = 0; i < whereClauses.Count; i++)
                {
                    builder.Append(whereClauses[i].Item1);
                    command.Parameters.AddRange(whereClauses[i].Item2.ToArray());

                    if (i < whereClauses.Count - 1)
                    {
                        builder.Append(" AND ");
                    }
                }
            }
        }