dotnet core 用SQLite 做数据库,跑集成测试,出现“table exist” 错误

2019-01-03 03:18发布

用SQLite 为数据库,在`.NET-Core` 上跑集成测试,发现第一次运行时,始终会出现下面的错误。 `Microsoft.Data.Sqlite.SqliteException : SQLite Error 1: 'table "XXX" already exists'.` 然后,第二次再次执行的话,就能够成功运行, 请问这是什么原因? 每次把.db 数据库文件删除第一次跑就会出现错误。

1条回答
我命由我不由天
2楼-- · 2019-01-03 03:58

使用 SQLite Memory 暂时没有出现上述错误。

var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = ":memory:" };
var connectionString = connectionStringBuilder.ToString();
var connection = new SqliteConnection(connectionString);
services.Configure(options => options.UseSqlite(connection));

Reference Link:
A DIFFERENT APPROACH TO TEST YOUR ASP.NET CORE APPLICATION

查看更多
登录 后发表回答