Added creation of database instance
This commit is contained in:
parent
d53966501a
commit
7b149417e7
@ -38,6 +38,25 @@ public static class Setup
|
||||
serviceCollection.AddDbContext<DataContext>(options => options.UseSqlite($"Filename={path2DataFile};Mode={(createWhenNecessary ? DB_READ_WRITE_CREATE_MODE : DB_READ_WRITE_MODE)};"), ServiceLifetime.Transient);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the database instance from the given path.
|
||||
/// </summary>
|
||||
public static DataContext CreateDatabaseInstance(string path2DataFile, bool createWhenNecessary = true)
|
||||
{
|
||||
// Store the path to the database:
|
||||
Setup.usedDataFile = path2DataFile;
|
||||
|
||||
// Create a database builder:
|
||||
var builder = new DbContextOptionsBuilder<DataContext>();
|
||||
|
||||
// Add the database configuration to the builder:
|
||||
builder.UseSqlite($"Filename={path2DataFile};Mode={(createWhenNecessary ? DB_READ_WRITE_CREATE_MODE : DB_READ_WRITE_MODE)};");
|
||||
|
||||
// Next, construct the database context:
|
||||
var dbContext = new DataContext(builder.Options);
|
||||
return dbContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the DI & db context ready for the EF tooling.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user