Table of Contents

Class SqliteDataContext

Namespace
NextORM.Sqlite
Assembly
nextorm.sqlite.dll

Data context for SQLite. Wraps the Microsoft.Data.Sqlite driver for connections and parameters, registers the SQLite function set on every connection and renders SQL through SqliteDialect.

public class SqliteDataContext : DataContext, IDataContext, IQueryExecutor, IQueryMaterializer, IQueryPlanner, IRowReaderFactory, IQueryCache, IContextEnvironment, IRawCommandExecutor, IAsyncDisposable, IDisposable, IConnectionManager, ITransactionManager
Inheritance
SqliteDataContext
Implements
Inherited Members
Extension Methods

Constructors

SqliteDataContext(DbConnection, DataContextBuilder)

Creates a SQLite context over a caller-supplied connection, which the context does not dispose.

public SqliteDataContext(DbConnection connection, DataContextBuilder optionsBuilder)

Parameters

connection DbConnection

An already-created DbConnection owned by the caller.

optionsBuilder DataContextBuilder

The options collected from DataContextBuilder.

SqliteDataContext(string, DataContextBuilder)

Creates a SQLite context that owns a connection built lazily from connectionString.

public SqliteDataContext(string connectionString, DataContextBuilder optionsBuilder)

Parameters

connectionString string

The connection string used to create the SqliteConnection.

optionsBuilder DataContextBuilder

The options collected from DataContextBuilder.

Properties

Dialect

SQL dialect used to render queries. Supplied by the provider; SQL generation depends on this interface rather than on the context itself.

public override ISqlDialect Dialect { get; }

Property Value

ISqlDialect

TimeOnlyProjectionRefusal

SQLite has no time-of-day type: a duration is an INTEGER tick count and a formatted value is TEXT. Reading either into a TimeOnly would reinterpret an integer or parse a string, so the projection is refused and a value converter must opt in explicitly.

protected override string? TimeOnlyProjectionRefusal { get; }

Property Value

string

Methods

CreateDbConnection(string?)

Creates a new SqliteConnection for connectionString.

protected override DbConnection CreateDbConnection(string? connectionString)

Parameters

connectionString string

The SQLite connection string.

Returns

DbConnection

A new, unopened SQLite connection.

CreateParam(string, object?)

Creates a SqliteParameter, mapping a null value to DBNull.Value because Microsoft.Data.Sqlite rejects an unset parameter value.

public override DbParameter CreateParam(string name, object? value)

Parameters

name string

The parameter name, without the provider prefix.

value object

The parameter value, or null.

Returns

DbParameter

A new SQLite parameter.

CreateProcedureParameter(ProcedureParameter)

Creates a SqliteParameter for a descriptor. A TableParameterValue is emulated as a JSON text parameter consumed with json_each(@p) (scalars) or json_extract(value, '$.col') (entities). A TypeName is SQL Server only and is rejected.

protected override DbParameter CreateProcedureParameter(ProcedureParameter parameter)

Parameters

parameter ProcedureParameter

The parameter descriptor.

Returns

DbParameter

A new SQLite parameter configured from parameter.

Exceptions

ArgumentException

TypeName is set (SQL Server only), or a table parameter is not Input.

OnConnectionCreated(DbConnection)

Registers the custom SQLite functions on connection so they are available to generated SQL.

protected override void OnConnectionCreated(DbConnection connection)

Parameters

connection DbConnection

The connection the context has just started using.