SqlServer.InMemory
0.1.5
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SqlServer.InMemory --version 0.1.5
NuGet\Install-Package SqlServer.InMemory -Version 0.1.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SqlServer.InMemory" Version="0.1.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SqlServer.InMemory" Version="0.1.5" />
<PackageReference Include="SqlServer.InMemory" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SqlServer.InMemory --version 0.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SqlServer.InMemory, 0.1.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SqlServer.InMemory@0.1.5
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SqlServer.InMemory&version=0.1.5
#tool nuget:?package=SqlServer.InMemory&version=0.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SqlServer.InMemory
SqlServer.InMemory is not a full SQL Server emulator. It is a testing-oriented EF Core provider/adapter that uses SQLite in-memory as the execution engine and adds SQL Server-inspired compatibility behavior.
The project is a proof of concept for automated tests that want a relational in-memory database with an API close to SQL Server-oriented EF Core setup:
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseSqlServerInMemory("TestDb")
.Options;
await using var context = new AppDbContext(options);
await context.Database.EnsureCreatedAsync(); // fast model-based setup
// Schema-oriented alternative; do not use both on the same database:
// await context.Database.MigrateAsync();
What it is
- A small EF Core adapter for tests.
- A SQLite in-memory backend hidden behind
UseSqlServerInMemory. - A place for SQL Server-inspired compatibility features.
- A foundation for a future partial T-SQL translator.
What it is not
- It is not SQL Server.
- It does not implement TDS,
SqlConnection, stored procedures, views, triggers, a query planner, or a full T-SQL parser. - It does not use Docker, Testcontainers, or a real SQL Server instance.
Projects
src/SqlServer.InMemory Core options, abstractions, and exceptions.
src/SqlServer.InMemory.Sqlite SQLite in-memory connection lifecycle and helpers.
src/SqlServer.InMemory.EFCore EF Core extension, schema normalization, and exception translation.
src/SqlServer.InMemory.TSql Future T-SQL translator contracts and basic translator POC.
tests/SqlServer.InMemory.Tests xUnit test coverage for the POC behavior.
Usage
using Microsoft.EntityFrameworkCore;
using SqlServer.InMemory.EFCore;
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseSqlServerInMemory("TestDb", sqlOptions =>
{
sqlOptions.EnforceForeignKeys = true;
sqlOptions.UseCaseInsensitiveCollation = true;
sqlOptions.SchemaMode = SqlServerInMemorySchemaMode.PrefixSchemaName;
})
.Options;
await using var context = new AppDbContext(options);
await context.Database.EnsureCreatedAsync(); // fast model-based setup
// Schema-oriented alternative; do not use both on the same database:
// await context.Database.MigrateAsync();
Implemented in this POC
UseSqlServerInMemoryfor typed and untypedDbContextOptionsBuilder.- SQLite in-memory connection opened immediately and kept alive by EF Core options.
PRAGMA foreign_keys = ONby default.SQLSERVER_CI_ASSQLite collation registration.- Schema normalization:
PrefixSchemaName:auth.Usersbecomesauth_Users.IgnoreSchema:auth.UsersbecomesUsers.
- Basic exception translation for SQLite foreign key and unique constraint errors.
- Automatic raw SQL translation through an EF Core command interceptor.
MigrateAsyncsupport through a custom migrations assembly and SQL generator that run migrations as SQL Server-oriented migrations and normalize operations for the SQLite in-memory backend.- SQLite table rebuild support for migration operations that SQLite cannot alter in place, such as dropping foreign keys, changing columns, and changing table constraints.
- Compatibility wrapper that accepts SQL Server
DbParameterinstances, includingMicrosoft.Data.SqlClient.SqlParameter, when the SQLite command is created. - Translation for common test-oriented T-SQL constructs:
dbo.,N'...',GETDATE(),DATEADD,ISNULL,COUNT_BIG,TOP,OFFSET/FETCH,SET IDENTITY_INSERT, guarded seed inserts,IF OBJECT_IDguards, andOUTPUT INSERTEDfor simple inserts. - Core custom exception types.
- Reset helper abstraction and SQLite implementation.
- T-SQL translator abstraction, no-op translator, and basic identifier/TOP translator.
Known limitations
- SQLite type behavior is not SQL Server type behavior.
- Case-insensitive collation is registered, but columns are not automatically rewritten to use it in every model scenario.
- Exception translation is intentionally narrow and based on SQLite error codes.
- Raw SQL translation is automatic, but it uses a regex-based translator intended for tests and known patterns.
- Migrations are executed by translating SQL Server-like migration operations to SQLite-compatible operations; unsupported SQL Server-only operations fail explicitly instead of silently passing.
- The basic translator is not a full T-SQL parser.
- Complex T-SQL such as
MERGE,OUTER APPLY, stored procedures, temporary tables, table variables, dynamic SQL, and arbitrary proceduralIF/ELSEblocks are still unsupported unless rewritten into supported patterns.
Roadmap
v0.1 — SQLite backend
- EF Core extension.
- SQLite in-memory.
- FK.
- Unique index.
- Not null.
- Schema normalization.
- Basic exception translation.
v0.2 — SQL Server-like behavior
- Better type mapping.
- Decimal handling.
- Datetime handling.
- Rowversion simulation.
- More SQL Server-like error messages.
- Better collation support.
v0.3 — T-SQL subset translator
- Identifiers.
- Schemas.
TOP.- Simple
SELECT. - Simple
INSERT. - Simple
UPDATE. - Simple
DELETE. - Simple
CREATE TABLE. - Simple
CREATE INDEX.
v0.4 — Raw SQL integration
- Translator diagnostics.
- Warnings for unsupported T-SQL.
- Configurable translator replacement.
- Optional explicit raw SQL helper APIs if needed.
Running tests
dotnet test SqlServer.InMemory.sln
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Data.Sqlite (>= 10.0.7)
- Microsoft.EntityFrameworkCore.Sqlite (>= 10.0.7)
- Microsoft.Extensions.DependencyInjection (>= 10.0.7)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.