Class SqliteDataContext
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
connectionDbConnectionAn already-created
DbConnectionowned by the caller.optionsBuilderDataContextBuilderThe 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
connectionStringstringThe connection string used to create the
SqliteConnection.optionsBuilderDataContextBuilderThe 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
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
Methods
CreateDbConnection(string?)
Creates a new SqliteConnection for connectionString.
protected override DbConnection CreateDbConnection(string? connectionString)
Parameters
connectionStringstringThe 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
namestringThe parameter name, without the provider prefix.
valueobjectThe 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
parameterProcedureParameterThe 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
connectionDbConnectionThe connection the context has just started using.