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();- 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.
- 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.
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.
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();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.
- 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.
- 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.
- 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.
- EF Core extension.
- SQLite in-memory.
- FK.
- Unique index.
- Not null.
- Schema normalization.
- Basic exception translation.
- Better type mapping.
- Decimal handling.
- Datetime handling.
- Rowversion simulation.
- More SQL Server-like error messages.
- Better collation support.
- Identifiers.
- Schemas.
TOP.- Simple
SELECT. - Simple
INSERT. - Simple
UPDATE. - Simple
DELETE. - Simple
CREATE TABLE. - Simple
CREATE INDEX.
- Translator diagnostics.
- Warnings for unsupported T-SQL.
- Configurable translator replacement.
- Optional explicit raw SQL helper APIs if needed.
dotnet test SqlServer.InMemory.sln