installation
Installation Microsoft.EntityFrameworkCore.Sqlite
NuGet package to * .EntityFrameworkCore project.
NOTE: Do not install into Microsoft.EntityFrameworkCore.Sqlite.Core will complain.
Configuration DbContext
Since SQLite does not support multi-threading, and should therefore be in * EntityFrameworkModule.PreInitialize()
disable transaction method.
public class 你的项目名称EntityFrameworkModule : AbpModule { public override void PreInitialize() { ... // add this line to disable transactions Configuration.UnitOfWork.IsTransactional = false; ... } }
Replace your project nameDbContextConfigurer.cs
public static class SqliteDemoDbContextConfigurer { public static void Configure(DbContextOptionsBuilder<SqliteDemoDbContext> builder, string connectionString) { builder.UseSqlite(connectionString); } public static void Configure(DbContextOptionsBuilder<SqliteDemoDbContext> builder, DbConnection connection) { builder.UseSqlite(connection); } }
Configuring the connection string
In * .Web.Mvc / appsettings.json will change the connection string to connect SQLite. example:
{ "ConnectionStrings": { "Default": "Data Source=SqliteDemoDb.db" }, ... }
Create a database
Before you create a database, delete * .EntityFrameworkCore / Migrations folder all migration under the category.
Note: Migrations folder in addition to Seed folder, the migration of other classes to be deleted, or otherwise does not always generate database table especially * bContextModelSnapshot does not delete the file will not create the table..
Now it is ready to build the database.
- Select * .Web.Mvc as the startup project.
- Open the package manager console and select * .EntityFrameworkCore project.
- Run
add-migration Initial_Migration
command - Run
update-database
command
SQLite integration is now complete.
hangfire integration with Sqlite
Installation Hangfire.SQLite.Core package
Modify Startup.cs
if (WebConsts.HangfireDashboardEnabled) { services.AddHangfire(config => { config.UseSQLiteStorage(_appConfiguration.GetConnectionString("Default")); }); } JobStorage.Current = new SQLiteStorage(_appConfiguration.GetConnectionString("Default"));
other problems
Integration with SQLite. Because of multithreading problems. Transaction can not be opened. Some code i need to be adjusted.
For example:.. Abp own event EntityCreatingEventData, EntityUpdatingEventData perform tasks such as abnormal ran after the data will not be rolled back