1

For Unit Testing, I am using EFCore SQLite in-memory db and creating schema as per the MS docs, but when the code attempts to execute EnsureDeleted(). It fails at with exception 'SQLite Error 1: ''.'

Not much details are provided in the exception and it fails provided below stacktrace.

First part of stacktrace: enter image description here

second part of stacktrace: enter image description here

The code uses Dotnet with version .net6.0 and for EFcore and Sqlite below are the packages with versions

<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="7.0.0" />

The code I use to make the connection is as below

var dbConnection = new SqliteConnection("Filename=:memory:");
dbConnection.Open();
var dbOptions = new DbContextOptionsBuilder<TestDBContext>()
    .UseSqlite(dbConnection, opt => opt.UseNetTopologySuite())
    .Options;

TestDBContext db = new TestDBContext(dbOptions);
db.Database.EnsureDeleted(); // This is where it fails.
db.Database.EnsureCreated();

  1. I have tried changing the connection string from "Filename=:memory:" to different variations.
  2. Tried adding or removing different packages.

Nothing has helped so far.

Arnab
  • 4,216
  • 2
  • 28
  • 50

1 Answers1

0

This is caused by Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite v7.0.0. You can try updating your code to

.UseSqlite(dbConnection)

and it should run with no problem.

The previous version v6.0.13 doesn't have this problem.

Twisted Whisper
  • 1,166
  • 2
  • 15
  • 27