Esempio n. 1
0
        private IDbCommand AssembleCommand <TFrom, TWhere>(bool isRetrieve, string selectClause, FromExpression <TFrom>?fromCondition, WhereExpression <TWhere>?whereCondition, IList <IDataParameter>?parameters)
            where TFrom : Entity, new()
            where TWhere : Entity, new()
        {
            IDbCommand command = _databaseEngine.CreateEmptyCommand();

            command.CommandType = CommandType.Text;
            command.CommandText = selectClause;

            if (isRetrieve)
            {
                if (fromCondition == null)
                {
                    fromCondition = NewFrom <TFrom>();
                }

                command.CommandText += fromCondition.ToString();

                foreach (KeyValuePair <string, object> pair in fromCondition.GetParameters())
                {
                    IDataParameter param = _databaseEngine.CreateParameter(pair.Key, pair.Value);
                    command.Parameters.Add(param);
                }
            }

            if (whereCondition != null)
            {
                command.CommandText += whereCondition.ToString();

                foreach (KeyValuePair <string, object> pair in whereCondition.GetParameters())
                {
                    IDataParameter param = _databaseEngine.CreateParameter(pair.Key, pair.Value);
                    command.Parameters.Add(param);
                }
            }

            if (parameters != null)
            {
                foreach (IDataParameter param in parameters)
                {
                    command.Parameters.Add(param);
                }
            }

            return(command);
        }
Esempio n. 2
0
 public IDbCommand CreateRetrieveCommand <TSelect, TFrom, TWhere>(SelectExpression <TSelect>?selectCondition, FromExpression <TFrom>?fromCondition, WhereExpression <TWhere>?whereCondition)
     where TSelect : Entity, new()
     where TFrom : Entity, new()
     where TWhere : Entity, new()
 {
     if (selectCondition == null)
     {
         return(AssembleCommand(true, GetSelectClauseStatement <TSelect, TFrom, TWhere>(), fromCondition, whereCondition, null));
     }
     else
     {
         return(AssembleCommand(true, selectCondition.ToString(), fromCondition, whereCondition, null));
     }
 }
Esempio n. 3
0
 public IDbCommand CreateCountCommand <T>(FromExpression <T>?fromCondition = null, WhereExpression <T>?whereCondition = null)
     where T : Entity, new()
 {
     return(AssembleCommand(true, "SELECT COUNT(1) ", fromCondition, whereCondition, null));
 }
Esempio n. 4
0
 public IDbCommand CreateRetrieveCommand <T1, T2, T3>(FromExpression <T1> fromCondition, WhereExpression <T1> whereCondition)
     where T1 : Entity, new()
     where T2 : Entity, new()
     where T3 : Entity, new()
 {
     return(AssembleCommand(true, GetSelectClauseStatement <T1, T2, T3>(), fromCondition, whereCondition, null));
 }
Esempio n. 5
0
 public IDbCommand CreateRetrieveCommand <T>(SelectExpression <T> selectCondition = null, FromExpression <T> fromCondition = null, WhereExpression <T> whereCondition = null)
     where T : DatabaseEntity, new()
 {
     if (selectCondition == null)
     {
         return(AssembleCommand(true, GetSelectClauseStatement <T>(), fromCondition, whereCondition, null));
     }
     else
     {
         return(AssembleCommand(true, selectCondition.ToString(), fromCondition, whereCondition, null));
     }
 }