Code配置DbConfiguration
https://msdn.microsoft.com/en-us/data/jj680699#Using
public class SQLiteConfiguration : DbConfiguration { public SQLiteConfiguration() { SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance); SetProviderFactory("System.Data.SQLite.EF6", SQLiteProviderFactory.Instance); Type t = Type.GetType( "System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"); FieldInfo fi = t.GetField("Instance", BindingFlags.NonPublic | BindingFlags.Static); SetProviderServices("System.Data.SQLite", (DbProviderServices)fi.GetValue(null)); } }
[DbConfigurationType(typeof(SQLiteConfiguration))] public class AdminContext : DbContext { public AdminContext() : base("name=AdminContext") { } public AdminContext(DbConnection db) : base(db, false) { } public DbSet<User> User { set; get; } }