SqlServer.InMemory 0.1.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package SqlServer.InMemory --version 0.1.4
                    
NuGet\Install-Package SqlServer.InMemory -Version 0.1.4
                    
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.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SqlServer.InMemory" Version="0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="SqlServer.InMemory" />
                    
Project file
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.4
                    
#r "nuget: SqlServer.InMemory, 0.1.4"
                    
#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.4
                    
#: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.4
                    
Install as a Cake Addin
#tool nuget:?package=SqlServer.InMemory&version=0.1.4
                    
Install as a Cake Tool

SqlServer.InMemory

NuGet

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

  • UseSqlServerInMemory for typed and untyped DbContextOptionsBuilder.
  • SQLite in-memory connection opened immediately and kept alive by EF Core options.
  • PRAGMA foreign_keys = ON by default.
  • SQLSERVER_CI_AS SQLite collation registration.
  • Schema normalization:
    • PrefixSchemaName: auth.Users becomes auth_Users.
    • IgnoreSchema: auth.Users becomes Users.
  • Basic exception translation for SQLite foreign key and unique constraint errors.
  • Automatic raw SQL translation through an EF Core command interceptor.
  • MigrateAsync support 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 DbParameter instances, including Microsoft.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_ID guards, and OUTPUT INSERTED for 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 procedural IF/ELSE blocks 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 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.7 29 5/20/2026
0.1.6 84 5/15/2026
0.1.5 81 5/15/2026
0.1.4 83 5/15/2026
0.1.3 90 5/14/2026
0.1.2 82 5/14/2026
0.1.1 90 5/12/2026
0.1.0 87 5/12/2026