Maybe this helps:
I uses a ContextBase and multiple implementations (e.g. SqLite, InMemory, SQL Server).
I didn't check the copy method, but this should work or be a useful base:
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace Foo
{
public class CopyData
{
public async void CopyAToB()
{
using var source = new FooSqliteContext("d:\\source.sqlite");
using var target = new FooInMemoryContext();
var sourceEntites = await source.Entites.ToArrayAsync();
target.Entites.AddRange(sourceEntites);
target.SaveChanges();
}
}
public abstract class FooContextBase : DbContext
{
public class Entity
{
public int Id { get; set; }
public string Name { get; set; }
}
public DbSet<Entity> Entites { get; set; }
}
public class FooInMemoryContext : FooContextBase
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseInMemoryDatabase("InMemoryDb");
}
public class FooSqliteContext : FooContextBase
{
public string SqLiteDbPath { get; set; }
public FooSqliteContext(string dbPathAndFile)
{
SqLiteDbPath = dbPathAndFile;
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite($"Data Source={SqLiteDbPath}");
}
}