Ejemplo n.º 1
0
        /// <summary>
        /// Returns a DELETE QueryCommand object to delete the records with
        /// matching passed column/value criteria
        /// </summary>
        /// <param name="columnName">Name of the column to match</param>
        /// <param name="oValue">Value of column to match</param>
        /// <returns></returns>
        public static QueryCommand GetDeleteCommand(string columnName, object oValue)
        {
            T            item = new T();
            QueryCommand cmd;

            TableSchema.Table       tbl          = item.GetSchema();
            TableSchema.TableColumn colDeleted   = tbl.GetColumn(ReservedColumnName.DELETED);
            TableSchema.TableColumn colIsDeleted = tbl.GetColumn(ReservedColumnName.IS_DELETED);

            if (colDeleted != null)
            {
                cmd = new Update(tbl).Set(colDeleted).EqualTo(true).Where(columnName).IsEqualTo(oValue).BuildCommand();
            }
            else if (colIsDeleted != null)
            {
                cmd = new Update(tbl).Set(colIsDeleted).EqualTo(true).Where(columnName).IsEqualTo(oValue).BuildCommand();
            }
            else
            {
                Query q = new Query(item.GetSchema())
                {
                    QueryType = QueryType.Delete
                };
                q.AddWhere(columnName, oValue);
                cmd = DataService.BuildCommand(q);
            }

            return(cmd);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Given an AbstractRecord object, returns a SELECT QueryCommand object used to generate SQL.
        /// </summary>
        /// <param name="item">The AbstractRecord object</param>
        /// <returns></returns>
        public static QueryCommand GetSelectCommand(RecordBase <T> item)
        {
            Query q = new Query(item.GetSchema());

            q.QueryType = QueryType.Select;
            QueryCommand cmd = DataService.BuildCommand(q);

            return(cmd);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a DELETE QueryCommand object to delete the record with
        /// the primary key value matching the passed value
        /// </summary>
        /// <param name="keyID">The primary key record value to match for the delete</param>
        /// <returns></returns>
        public static QueryCommand GetDeleteCommand(object keyID)
        {
            T     item = new T();
            Query q    = new Query(item.GetSchema());

            q.QueryType = QueryType.Delete;
            q.AddWhere(q.Schema.PrimaryKey.ColumnName, keyID);

            return(DataService.BuildCommand(q));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Deletes the record in the table, even if it contains Deleted or IsDeleted flag columns
        /// </summary>
        /// <param name="columnName">The name of the column that whose value will be evaluated for deletion</param>
        /// <param name="oValue">The value that will be compared against columnName to determine deletion</param>
        /// <returns>Number of rows affected by the operation</returns>
        public static int DestroyByParameter(string columnName, object oValue)
        {
            T     item = new T();
            Query q    = new Query(item.GetSchema());

            q.QueryType = QueryType.Delete;
            q.AddWhere(columnName, oValue);
            QueryCommand cmd = DataService.BuildCommand(q);

            return(DataService.ExecuteQuery(cmd));
        }