Creatio development guide
This documentation is valid for Creatio version 7.14.0. We recommend using the newest version of Creatio documentation.

Deleting data. The Delete class

Glossary Item Box

Introduction

The Terrasoft.Core.DB.Delete class is used to build queries for deleting records in bpm’online database tables. As a result of creating and configuring the instance of this class, the DELETE SQL-expression query to the application database will be built.

The Terrasoft.Core.DB.Delete class

NOTE

Use the “.NET class libraries of platform core” documentation to access the full list of the Delete class methods and properties, its parent classes and the implemented interfaces.

Constructors

  • public Delete(UserConnection userConnection) – creates a class instance using UserConnection
  • public Delete(Delete source) – creates a class instance that is a clone of the instance passed as an argument

Properties

Table 1. Primary properties of the class

Property Type Description
UserConnection Terrasoft.Core.UserConnection The current user connection at the moment of executing the query.
Condition Terrasoft.Core.DB.QueryCondition Condition of Where expression in the query.
HasCondition bool Determines whether Where expression is available in the query.
Source. Terrasoft.Core.DB.ModifyQuerySource The query data source.

Methods

Table 2. Primary methods of the class

Methods Description
string GetSqlText() Returns the SQL text of the current query.
void BuildSqlText(StringBuilder sb) Generates the query text via the StringBuilder instance.
void ResetCachedSqlText() Clears the cached text of the query.
QueryParameterCollection GetUsingParameters() Returns the collection of parameters used by the query.

int Execute()

Executes the query. Returns the number of records involved by the query.

int Execute(DBExecutor dbExecutor)

Executes the query using the DBExecutor instance. Returns the number of records involved by the query.

QueryCondition Where()

QueryCondition Where(string sourceColumnAlias)

QueryCondition Where(string sourceAlias, string sourceColumnAlias)

QueryCondition Where(Select subSelect)

QueryCondition Where(Query subSelectQuery)

QueryCondition Where(QueryColumnExpression columnExpression)

Query Where(QueryCondition condition)

Adds the initial condition to the current query.

Parameters:

  • sourceColumnAlias – an alias of the column for which the condition is added
  • sourceAlias – the alias of the source
  • subSelect – a subquery of the data selection, for whose results the condition is added
  • subSelectQuery – the subquery, for whose results the condition is added
  • columnExpression – the expression, for whose results the condition is added
  • condition – the query condition

QueryCondition And()

QueryCondition And(string sourceColumnAlias)

QueryCondition And(string sourceAlias, string sourceColumnAlias)

QueryCondition And(Select subSelect)

QueryCondition And(Query subSelectQuery)

QueryCondition And(QueryParameter parameter)

QueryCondition And(QueryColumnExpression columnExpression)

Query And(QueryCondition condition)

Adds the condition (predicate) to the current query condition using the AND logical operation.

Parameters:

  • sourceColumnAlias – an alias of the column, for which the predicate is added
  • sourceAlias – the alias of the source
  • subSelect – the data selection subquery used as a predicate
  • subSelectQuery – the subquery used as a predicate
  • parameter – parameter that the predicate is added to
  • columnExpression – the expression used as a predicate
  • condition – the query condition

QueryCondition Or()

QueryCondition Or(string sourceColumnAlias)

QueryCondition Or(string sourceAlias, string sourceColumnAlias)

QueryCondition Or(Select subSelect)

QueryCondition Or(Query subSelectQuery)

QueryCondition Or(QueryParameter parameter)

QueryCondition Or(QueryColumnExpression columnExpression)

Query Or(QueryCondition condition)

Adds the condition (predicate) to the current query condition using the OR logical operation.

Parameters:

  • sourceColumnAlias – an alias of the column, for which the predicate is added
  • sourceAlias – the alias of the source
  • subSelect – the data selection subquery used as a predicate
  • subSelectQuery – the subquery used as a predicate
  • parameter – parameter that the predicate is added to
  • columnExpression – the expression used as a predicate
  • condition – the query condition

Delete From(string schemaName)

Delete From(ModifyQuerySource source)

Adds the data source to the current query. Returns the current Delete instance.

Parameters:

  • schemaName— schema name (tables, views)
  • source – the data source

 

Use cases

You can download the package with the configuration web serice implementing the below described cases using the following link.

ATTENTION

In most cases, the request for deletion should contain the Where condition, which specifies which records exactly should be deleted. Otherwise, all records will be deleted.

Example 1

Receive the SQL-query text.

public string GetSqlTextExample(string name)
{
    var result = "";
    var delete = new Delete(UserConnection)
        .From("Contact")
        .Where("Name").IsEqual(Column.Const(name));
    result = delete.GetSqlText();
    return result;
}

Example 2

Change the contact name for a new one.

public string DeleteContacts(string name)
{
    var delete = new Delete(UserConnection)
        .From("Contact")
        .Where("Name").IsEqual(Column.Parameter(name));
    var cnt = delete.Execute();
    return $"Contacts with name {name} were deleted. {cnt} rows affected";
}

© bpm'online 2002-2019.

Did you find this information useful?

How can we improve it?