Table of Contents

Class LegacyMergeExtensions

Namespace
LinqToDB.Data
Assembly
linq2db.dll

Contains extension methods for DataConnection class.

[Obsolete("Legacy Merge API obsoleted and not recommended for use. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/LegacyMergeExtensions.cs.")]
public static class LegacyMergeExtensions
Inheritance
LegacyMergeExtensions
Inherited Members

Methods

MergeAsync<T>(DataConnection, bool, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)

Executes following merge operations asynchronously in specified order:

  • Update
  • Insert
  • Delete By Source (optional). If delete operation enabled by delete parameter - method could be used only with SQL Server.
public static Task<int> MergeAsync<T>(this DataConnection dataConnection, bool delete, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class

Parameters

dataConnection DataConnection

Data connection instance.

delete bool

If true, merge command will include delete by source operation without condition.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

cancellationToken CancellationToken

Optional asynchronous operation cancellation token.

Returns

Task<int>

Task with number of affected target records.

Type Parameters

T

Target table mapping class.

MergeAsync<T>(DataConnection, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)

Executes following merge operations asynchronously in specified order:

  • Update
  • Insert.
public static Task<int> MergeAsync<T>(this DataConnection dataConnection, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class

Parameters

dataConnection DataConnection

Data connection instance.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

cancellationToken CancellationToken

Optional asynchronous operation cancellation token.

Returns

Task<int>

Task with number of affected target records.

Type Parameters

T

Target table mapping class.

MergeAsync<T>(DataConnection, Expression<Func<T, bool>>, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)

Executes following merge operations asynchronously in specified order:

  • Update
  • Insert
  • Delete By Source. Method could be used only with SQL Server.
public static Task<int> MergeAsync<T>(this DataConnection dataConnection, Expression<Func<T, bool>> predicate, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class

Parameters

dataConnection DataConnection

Data connection instance.

predicate Expression<Func<T, bool>>

Filter, applied to delete operation. Optional.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

cancellationToken CancellationToken

Optional asynchronous operation cancellation token.

Returns

Task<int>

Task with number of affected target records.

Type Parameters

T

Target table mapping class.

MergeAsync<T>(DataConnection, IQueryable<T>, Expression<Func<T, bool>>, string?, string?, string?, string?, TableOptions, CancellationToken)

Executes following merge operations asynchronously in specified order:

  • Update
  • Insert
  • Delete By Source. Method could be used only with SQL Server.
public static Task<int> MergeAsync<T>(this DataConnection dataConnection, IQueryable<T> source, Expression<Func<T, bool>> predicate, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class

Parameters

dataConnection DataConnection

Data connection instance.

source IQueryable<T>

Source data to merge into target table. All source data will be loaded from server for command generation.

predicate Expression<Func<T, bool>>

Filter, applied both to source and delete operation. Required.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

cancellationToken CancellationToken

Optional asynchronous operation cancellation token.

Returns

Task<int>

Task with number of affected target records.

Type Parameters

T

Target table mapping class.

MergeAsync<T>(ITable<T>, bool, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)

Executes following merge operations asynchronously in specified order:

  • Update
  • Insert
  • Delete By Source (optional). If delete operation enabled by delete parameter - method could be used only with SQL Server.
public static Task<int> MergeAsync<T>(this ITable<T> table, bool delete, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class

Parameters

table ITable<T>

Target table.

delete bool

If true, merge command will include delete by source operation without condition.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

cancellationToken CancellationToken

Optional asynchronous operation cancellation token.

Returns

Task<int>

Task with number of affected target records.

Type Parameters

T

Target table mapping class.

MergeAsync<T>(ITable<T>, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)

Executes following merge operations asynchronously in specified order:

  • Update
  • Insert.
public static Task<int> MergeAsync<T>(this ITable<T> table, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class

Parameters

table ITable<T>

Target table.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

cancellationToken CancellationToken

Optional asynchronous operation cancellation token.

Returns

Task<int>

Task with number of affected target records.

Type Parameters

T

Target table mapping class.

MergeAsync<T>(ITable<T>, Expression<Func<T, bool>>, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)

Executes following merge operations asynchronously in specified order:

  • Update
  • Insert
  • Delete By Source. Method could be used only with SQL Server.
public static Task<int> MergeAsync<T>(this ITable<T> table, Expression<Func<T, bool>> predicate, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class

Parameters

table ITable<T>

Target table.

predicate Expression<Func<T, bool>>

Filter, applied to delete operation. Optional.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

cancellationToken CancellationToken

Optional asynchronous operation cancellation token.

Returns

Task<int>

Task with number of affected target records.

Type Parameters

T

Target table mapping class.

MergeAsync<T>(ITable<T>, IQueryable<T>, Expression<Func<T, bool>>, string?, string?, string?, string?, TableOptions, CancellationToken)

Executes following merge operations asynchronously in specified order:

  • Update
  • Insert
  • Delete By Source. Method could be used only with SQL Server.
public static Task<int> MergeAsync<T>(this ITable<T> table, IQueryable<T> source, Expression<Func<T, bool>> predicate, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class

Parameters

table ITable<T>

Target table.

source IQueryable<T>

Source data to merge into target table. All source data will be loaded from server for command generation.

predicate Expression<Func<T, bool>>

Filter, applied both to source and delete operation. Required.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

cancellationToken CancellationToken

Optional asynchronous operation cancellation token.

Returns

Task<int>

Task with number of affected target records.

Type Parameters

T

Target table mapping class.

Merge<T>(DataConnection, bool, IEnumerable<T>, string?, string?, string?, string?, TableOptions)

Executes following merge operations in specified order:

  • Update
  • Insert
  • Delete By Source (optional). If delete operation enabled by delete parameter - method could be used only for with Server.
public static int Merge<T>(this DataConnection dataConnection, bool delete, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class

Parameters

dataConnection DataConnection

Data connection instance.

delete bool

If true, merge command will include delete by source operation without condition.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

Returns

int

Returns number of affected target records.

Type Parameters

T

Target table mapping class.

Merge<T>(DataConnection, IEnumerable<T>, string?, string?, string?, string?, TableOptions)

Executes following merge operations in specified order:

  • Update
  • Insert.
public static int Merge<T>(this DataConnection dataConnection, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class

Parameters

dataConnection DataConnection

Data connection instance.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

Returns

int

Returns number of affected target records.

Type Parameters

T

Target table mapping class.

Merge<T>(DataConnection, Expression<Func<T, bool>>, IEnumerable<T>, string?, string?, string?, string?, TableOptions)

Executes following merge operations in specified order:

  • Update
  • Insert
  • Delete By Source. Method could be used only with SQL Server.
public static int Merge<T>(this DataConnection dataConnection, Expression<Func<T, bool>> predicate, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class

Parameters

dataConnection DataConnection

Data connection instance.

predicate Expression<Func<T, bool>>

Filter, applied to delete operation. Optional.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

Returns

int

Returns number of affected target records.

Type Parameters

T

Target table mapping class.

Merge<T>(DataConnection, IQueryable<T>, Expression<Func<T, bool>>, string?, string?, string?, string?, TableOptions)

Executes following merge operations in specified order:

  • Update
  • Insert
  • Delete By Source. Method could be used only with SQL Server.
public static int Merge<T>(this DataConnection dataConnection, IQueryable<T> source, Expression<Func<T, bool>> predicate, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class

Parameters

dataConnection DataConnection

Data connection instance.

source IQueryable<T>

Source data to merge into target table. All source data will be loaded from server for command generation.

predicate Expression<Func<T, bool>>

Filter, applied both to source and delete operation. Required.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

Returns

int

Returns number of affected target records.

Type Parameters

T

Target table mapping class.

Merge<T>(ITable<T>, bool, IEnumerable<T>, string?, string?, string?, string?, TableOptions)

Executes following merge operations in specified order:

  • Update
  • Insert
  • Delete By Source (optional). If delete operation enabled by delete parameter - method could be used only with SQL Server.
public static int Merge<T>(this ITable<T> table, bool delete, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class

Parameters

table ITable<T>

Target table.

delete bool

If true, merge command will include delete by source operation without condition.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

Returns

int

Returns number of affected target records.

Type Parameters

T

Target table mapping class.

Merge<T>(ITable<T>, IEnumerable<T>, string?, string?, string?, string?, TableOptions)

Executes following merge operations in specified order:

  • Update
  • Insert.
public static int Merge<T>(this ITable<T> table, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class

Parameters

table ITable<T>

Target table.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

Returns

int

Returns number of affected target records.

Type Parameters

T

Target table mapping class.

Merge<T>(ITable<T>, Expression<Func<T, bool>>, IEnumerable<T>, string?, string?, string?, string?, TableOptions)

Executes following merge operations in specified order:

  • Update
  • Insert
  • Delete By Source. Method could be used only with SQL Server.
public static int Merge<T>(this ITable<T> table, Expression<Func<T, bool>> predicate, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class

Parameters

table ITable<T>

Target table.

predicate Expression<Func<T, bool>>

Filter, applied to delete operation. Optional.

source IEnumerable<T>

Source data to merge into target table.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

Returns

int

Returns number of affected target records.

Type Parameters

T

Target table mapping class.

Merge<T>(ITable<T>, IQueryable<T>, Expression<Func<T, bool>>, string?, string?, string?, string?, TableOptions)

Executes following merge operations in specified order:

  • Update
  • Insert
  • Delete By Source. Method could be used only with SQL Server.
public static int Merge<T>(this ITable<T> table, IQueryable<T> source, Expression<Func<T, bool>> predicate, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class

Parameters

table ITable<T>

Target table.

source IQueryable<T>

Source data to merge into target table. All source data will be loaded from server for command generation.

predicate Expression<Func<T, bool>>

Filter, applied both to source and delete operation. Required.

tableName string

Optional target table name.

databaseName string

Optional target table's database name.

schemaName string

Optional target table's schema name.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Table options. See TableOptions enum for support information per provider.

Returns

int

Returns number of affected target records.

Type Parameters

T

Target table mapping class.