Class DmlServiceBase
- Namespace
- LinqToDB.Internal.DataProvider
- Assembly
- linq2db.dll
Base class for provider-specific IDmlService implementations. By default BuildCommandScenario(SqlStatement, SqlProviderFlags, ISqlExpressionFactory) returns a single-step scenario (one statement rendered as one command), or the InsertOrReplace/Upsert emulation for those statements; providers override it for identity, truncate-reset, etc. PlanScenario(SqlCommandScenario, SqlProviderFlags) defaults to all-singleton (sequential) groups.
public abstract class DmlServiceBase : IDmlService
- Inheritance
-
objectDmlServiceBase
- Implements
- Derived
- Extension Methods
Methods
BuildCommandScenario(SqlStatement, SqlProviderFlags, ISqlExpressionFactory)
Builds the command scenario for statement. The base handles the InsertOrReplace / Upsert
emulation and otherwise returns a single-step DefaultScenario(SqlStatement) (one statement, one command).
Providers override to build an explicit multi-step scenario (identity retrieval, per-field truncate reset,
etc.), using factory to construct any synthetic statements (e.g. an identity SELECT),
and delegate the default case back here via base.BuildCommandScenario(...).
public virtual SqlCommandScenario? BuildCommandScenario(SqlStatement statement, SqlProviderFlags flags, ISqlExpressionFactory factory)
Parameters
statementSqlStatementflagsSqlProviderFlagsfactoryISqlExpressionFactory
Returns
BuildInsertOrUpdateScenario(SqlInsertOrUpdateStatement, SqlProviderFlags, ISqlExpressionFactory)
Reshapes an InsertOrReplace / Upsert / InsertOrUpdate statement into the UPDATE→INSERT emulation when the provider's native single-statement upsert can't honor it (see WillEmulateInsertOrUpdate(SqlInsertOrUpdateStatement, SqlProviderFlags)); returns null to let the builder render the native form. Running here — rather than at query-build time — means remote data contexts rebuild the same gated scenario server-side from the serialized statement. Three gated shapes, matching the legacy orchestration:
- UPDATE, then INSERT when it affected no rows (Update.Items present, no UPDATE predicate);
- existence-SELECT, then INSERT when absent (Update.Items empty — nothing to update);
- existence-SELECT, then UPDATE when present / INSERT when absent (Upsert.Update.When predicate).
protected static SqlCommandScenario? BuildInsertOrUpdateScenario(SqlInsertOrUpdateStatement statement, SqlProviderFlags flags, ISqlExpressionFactory factory)
Parameters
statementSqlInsertOrUpdateStatementflagsSqlProviderFlagsfactoryISqlExpressionFactory
Returns
DefaultScenario(SqlStatement)
The trivial scenario for a self-contained statement: one step rendered as one command. The step
Kind is not consulted for a lone simple command — the runner's fast path
dispatches by the called Execute* method — so NonQuery is an arbitrary
placeholder here; OutcomeSteps points at the single step.
protected static SqlCommandScenario DefaultScenario(SqlStatement statement)
Parameters
statementSqlStatement
Returns
HResultMatches(Exception, int)
True if exception's HResult matches
hResult, or the remote-transport message wrapper contains the
canonical hex form ("0x1234ABCD").
protected static bool HResultMatches(Exception exception, int hResult)
Parameters
Returns
IdentitySelectScenario(SqlStatement, ISqlExpression)
The two-step identity-insert scenario: the INSERT executed as a non-query, then a scalar SELECT of the
generated key (identity, e.g. @@IDENTITY / LAST_INSERT_ID()). The SELECT is
the outcome. Providers differ only in the identity expression; the step shape lives here.
protected static SqlCommandScenario IdentitySelectScenario(SqlStatement insert, ISqlExpression identity)
Parameters
insertSqlStatementidentityISqlExpression
Returns
IsTableNotFoundException(Exception)
Returns true if the given exception indicates the target table does not exist.
Used by DropTable to decide whether a "not exists" suppression request should
swallow a given error.
public bool IsTableNotFoundException(Exception exception)
Parameters
exceptionException
Returns
IsTableNotFoundExceptionCore(Exception)
Detects a provider-specific "table not found" exception. Called for every link of the inner-exception chain.
protected abstract bool IsTableNotFoundExceptionCore(Exception exception)
Parameters
exceptionException
Returns
PerFieldResetScenario(SqlTruncateTableStatement, Func<SqlField, SqlStatement>)
The truncate-with-identity-reset scenario: the TRUNCATE as a non-query (the outcome), followed by one reset
statement per identity column, built by reset. For providers whose reset is a per-column
ALTER TABLE … fragment (the template and name quoting differ per provider).
protected static SqlCommandScenario PerFieldResetScenario(SqlTruncateTableStatement truncate, Func<SqlField, SqlStatement> reset)
Parameters
truncateSqlTruncateTableStatementresetFunc<SqlField, SqlStatement>
Returns
PlanScenario(SqlCommandScenario, SqlProviderFlags)
Plans physical command groups. Without IsMultiStatementBatchSupported — or around a gated step (which must be evaluated client-side before it runs) — every step is its own group (today's sequential behavior). Otherwise a maximal run of contiguous non-gated steps is combined; a single combined command may harvest more than one result-producing step only when IsMultipleResultSetsSupported is set — otherwise the run is split so each combined group holds at most one result-producing step.
public virtual SqlCommandGroupPlan PlanScenario(SqlCommandScenario scenario, SqlProviderFlags flags)
Parameters
scenarioSqlCommandScenarioflagsSqlProviderFlags
Returns
TypeOrMessageContains(Exception, string)
Matches marker against the exception's type name or its message.
The message check is needed for remote (gRPC / HTTP) data contexts where the original
provider exception is wrapped — the type name survives only as text inside the
wrapping exception's Message (populated via ToString()).
protected static bool TypeOrMessageContains(Exception exception, string marker)