Esempio n. 1
0
        protected int DeleteRows(string table_name)
        {
            DataTable         myTable = this.Tables[table_name];
            DataRowCollection rows    = myTable.Rows;
            int rowsCount             = rows.Count;
            int rowsAffected          = 0;

            if (rowsCount == 0)
            {
                return(0);
            }

            DeleteStatement cmd = new DeleteStatement(myTable.ExtendedProperties["Storage"].ToString());

            cmd.ConnectionStringName = _connectionStringName;
            List <SqlParameter> prmlist = new List <SqlParameter>();
            int    colsCount            = myTable.Columns.Count;
            int    keys     = 0;
            string identcol = String.Empty;

            for (int c = 0; c < colsCount; c++)
            {
                DataColumn col = myTable.Columns[c];

                if (col.ExtendedProperties["PrimaryKey"] != null)
                {
                    SqlParameter prm = new SqlParameter(col.ColumnName, col.DataType);
                    prmlist.Add(prm);
                    cmd.Where(Condition.IsEqual(col.ExtendedProperties["Storage"].ToString(), prm));
                    keys++;
                }
            }

            List <DataRow> toDelete = new List <DataRow>();

            foreach (DataRow row in myTable.Rows)
            {
                if (row.RowState == DataRowState.Deleted)
                {
                    for (int p = 0; p < keys; p++)
                    {
                        SqlParameter prm = prmlist[p];
                        prm.Value = row[prm.Name, DataRowVersion.Original];
                    }

                    cmd.Execute();
                    toDelete.Add(row);
                    rowsAffected++;
                }
            }
            toDelete.ForEach(delegate(DataRow row) { row.AcceptChanges(); });


            return(rowsAffected);
        }
Esempio n. 2
0
        public virtual void Delete(ICondition filter)
        {
            if (filter == null)
            {
                return;
            }

            var delete = new DeleteStatement(_tableName)
            {
                ConnectionStringName = _connectionStringName
            };

            delete.Where(filter);
            delete.Execute();
        }
Esempio n. 3
0
        public static DeleteStatement CreateDeleteStatement(IMapping mapping, bool include_all_fields)
        {
            DeleteStatement statement = new DeleteStatement(mapping.TableName);

            foreach (var item in mapping.Columns)
            {
                if (include_all_fields || (include_all_fields && item.IsPrimaryKey))
                {
                    var          pinfo = (PropertyInfo)item.Property;
                    SqlParameter prm   = statement.CreateParameter(item.Name, pinfo.PropertyType);
                    statement.Where(new Condition(item.ColumnName, Comparisons.Equals, prm));
                }
            }

            return(statement);
        }