Exemple #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Joinable(iQueryBuilder pQuery)
     : base(pQuery)
 {
     Where = new Conditions(pQuery);
     Type = eJOIN.LEFT;
     JoinTables = new List<JoinTable>();
 }
Exemple #2
0
        /// <summary>
        /// Adds a model to the current list of joined tables. The join
        /// type has to be the same.
        /// </summary>
        public iQueryBuilder Join(eJOIN pJoinType, bool pAuto, Model pModel, IEnumerable<string> pFields)
        {
            Join(pJoinType, pModel.Settings.Table, pFields);

            if (!pAuto)
            {
                return Query();
            }

            string foreignKey = string.Format("{0}_id", Inflector.Underscore(Query().Model().Settings.Alias));
            string id = Query().Model().Settings.PrimaryKey;

            Where.Expression(id, string.Format("= {0}", pModel.Field(foreignKey)));

            return Query();
        }
Exemple #3
0
        /// <summary>
        /// Adds a model to the current list of joined tables. The join
        /// type has to be the same.
        /// </summary>
        public iQueryBuilder Join(eJOIN pJoinType, string pTable, IEnumerable<string> pFields)
        {
            if (Query().Type() == QueryBuilder.eTYPE.INSERT)
            {
                throw new ModelException("Cannot JOIN on an INSERT statement.");
            }
            if (Type == eJOIN.NONE)
            {
                Type = pJoinType;
            }
            if (Type != pJoinType)
            {
                throw new ModelException("JOIN type already set for query as {0} JOIN", Type);
            }

            JoinTables.Add(new JoinTable(Query(), pTable, pFields));

            return Query();
        }
Exemple #4
0
 /// <summary>
 /// Adds a model to the current list of joined tables. The join
 /// type has to be the same.
 /// </summary>
 public iQueryBuilder Join(eJOIN pJoinType, string pTable, IEnumerable<string> pFields)
 {
     return ((iJoinable)Joins).Join(pJoinType, pTable, pFields);
 }
Exemple #5
0
 /// <summary>
 /// Adds a model to the current list of joined tables. The join
 /// type has to be the same.
 /// </summary>
 public iQueryBuilder Join(eJOIN pJoinType, bool pAuto, Model pModel, IEnumerable<string> pFields)
 {
     return ((iJoinable)Joins).Join(pJoinType, pAuto, pModel, pFields);
 }