Skip to content

BH.oM.Adapters.SQL.UpsertCommand

Specify objects to update or insert (upsert) depending on whether existing data exists. If the data does not exist based on the Primary Key given, then the data is inserted into the table. If the data did previously exist, then its columns are updated.

Class structure

Implemented interfaces and base types

The UpsertCommand is inheriting from the following base type(s) and implements the following interfaces:

Properties

Defining properties

The following properties are defined on the class

Name Type Description Quantity
PrimaryKey string Specify the primary key of the data used to identify existing data to update, or to insert if the data does not exist. -
DefaultPrimaryKeyValue object Specify what the default value of your primary key is to determine whether data should be updated or inserted. E.G. if your primary key is 'ID' and is of type 'int', then specify 0 for objects which are new and need inserting. -
PrimaryKeyType Type Set the type of the primary key value - used to ensure queried properties from objects to upsert match the right type and the DefaultPrimaryKeyValue is correctly casted to this type. -
ObjectsToUpsert List<object> List of objects which are to be upserted into the database. Objects must all be of a single type. -
Table string The name of the table which the data should be upserted to. -

Code and Schema

C# implementation

C#
public class UpsertCommand : BH.oM.Adapter.IExecuteCommand, BH.oM.Base.IObject

Assembly: SQL_oM.dll

The C# class definition is available on github:

All history and changes of the class can be found by inspection the history.

JSON Schema implementation

The object is defined as a JSON schema. You can validate a JSON instance against this schema by reference. To do this, use the schema reference below in a validator like this one.

JSON Schema
{
 "$ref" : "https://raw.githubusercontent.com/BHoM/BHoM_JSONSchema/develop/SQL_oM/UpsertCommand.json"
}

The JSON Schema is available on github here: