Composing add data queries
Glossary Item Box
The Insert class is used to add data to the bpm'online database.
The Insert class constructor uses the following objects as parameters:
- User connection (Insert (UserConnection)).
- Other object Insert (Insert (Insert)). This will create a copy of an Insert request included in the parameter.
Examples of simple requests
Example 1.
var insert = new Insert(userConnection).Into("Contact") .Set("Name", Column.Parameter("ParameterNameValue")) .Set("Address", Column.Parameter("ParameterAddressValue")); insert.Execute(); |
INSERT INTO [dbo].[Contact] ([Name], [Address]) VALUES (@P1, @P2)
|
Example 2
var insert = new Insert(userConnection).Into("Contact") .Set("Name", Column.Const("NameValue")) .Set("Address", Column.Const("AddressValue")); insert.Execute(); |
INSERT INTO [dbo].[Contact] ([Name], [Address]) VALUES ('NameValue', 'AddressValue')
|
Example 3
var insert = new Insert(userConnection).Into("Contact") .Set("Name", Func.IsNull(Column.Parameter(string.Empty), Column.Parameter("ParameterValue"))); insert.Execute(); |
INSERT INTO [dbo].[Contact] ([Name]) VALUES (ISNULL(@P1, @P2))
|
Examples of requests with conditions
Example 1
var insert = new Insert(userConnection).Into("City") .Set("CreatedById", new Select(userConnection).Top(1) .Column("Id") .From("Contact") .Where("Name").IsEqual(Column.Parameter("Supervisor"))) .Set("ModifiedById", new Select(userConnection).Top(1) .Column("Id") .From("Contact") .Where("Name").IsEqual(Column.Parameter("User1"))); insert.Execute(); |
INSERT INTO [dbo].[City] ([CreatedById], [ModifiedById]) VALUES((SELECT TOP 1 [Id] FROM [dbo].[Contact] WHERE [Name] = @P1), (SELECT TOP 1 [Id] FROM [dbo].[Contact] WHERE [Name] = @P2)) |