简体   繁体   中英

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

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, IList 1 entities, TableInfo tableInfo, OperationType operationType, Action 1 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM