EFCore Bulk Insert & SQLite In Memory: no such table: INFORMATION_SCHEMA.COLUMNS"

c# entity-framework-core in-memory-database sqlbulkcopy sqlite

Question

I'm using EFCore BulkExtensions 2.5.0 with Entity Framework Core 2.2.3 and EFCore.SQLite 2.2.6.

I have code like this:

// Repo that throws exception on BulkInsert
public class UserRepository
{
   private readonly IDbContextProvider<ReportContext> _dbContextProvider;

   public async Sync(IList<User> users)
   { 
        await _dbContextProvider.Context.BulkInserOrUpdateAsync(users);
   }
}

// Poco Model
public class User
{
   public string Id {get;set;}
   public string Name {get; set;}
}

// Simple DbContext
public class ReportsContext : DbContext
{
   public DbSet<User> Users { get; set; }
}

My application code (which uses EFCore.Sql) runs this just fine. But when my test code runs using SQLite in-memory, I get an exception:

No such table: INFORMATION_SCHEMA.COLUMNS

Microsoft.Data.Sqlite.SqliteException : SQLite Error 1: 'no such table: INFORMATION_SCHEMA.COLUMNS'.

at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteCommand.PrepareAndEnumerateStatements(Stopwatch timer)+MoveNext()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at EFCore.BulkExtensions.TableInfo.CheckHasIdentityAsync(DbContext context, CancellationToken cancellationToken)
at EFCore.BulkExtensions.SqlBulkOperation.MergeAsync[T](DbContext context, IList1 entities, TableInfo tableInfo, OperationType operationType, Action1 progress, CancellationToken cancellationToken)
at MyCode.Repositories.UserRepository.<>c__DisplayClass5_0.<b__0>d.MoveNext() in C:\projects\MyCode\Repositories\UserRepository.cs:line 48

INFORMATION_SCHEMA.COLUMNS isn't part of my data model and isn't something I'm trying to create or work with. Do I need to configure or tweak EF Core or SQLite to get it to support bulk operations when operation in-memory mode?

I've tried turning on EF Core logging and can see my Db Model being processed and tables being created, but no output on the bulk operations, so I'm unsure what generated SQL statements are looking for this Information_Schema.Columns table.

1
0
3/15/2020 9:38:09 PM

Accepted Answer

Looks like this is a bug in EFCore.BulkExtensions for 2.5.0 where it didn't have full SQLite support. It works with version 2.6.4: https://github.com/borisdj/EFCore.BulkExtensions/issues/308

0
3/17/2020 8:13:19 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow