Skip to content

Commit e4d0193

Browse files
committed
fixes #45
This will create any folder for the database file if it doesn't exists. connString:data source=.\db\footballDb\footballDb.sqlite Folder .\db\footballDb\ will be created in InitializeDatabase
1 parent 5b86ce2 commit e4d0193

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

SQLite.CodeFirst.Console/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
55
</configSections>
66
<connectionStrings>
7-
<add name="footballDb" connectionString="data source=.\footballDb.sqlite;foreign keys=true" providerName="System.Data.SQLite" />
7+
<add name="footballDb" connectionString="data source=.\db\footballDb\footballDb.sqlite;foreign keys=true" providerName="System.Data.SQLite" />
88
</connectionStrings>
99
<startup>
1010
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />

SQLite.CodeFirst/SqliteInitializerBase.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ public virtual void InitializeDatabase(TContext context)
6060
{
6161
var model = modelBuilder.Build(context.Database.Connection);
6262

63+
//mprattinger: Possible fix for #45
64+
var dbFile = GetDatabasePathFromContext(context);
65+
var dbFileInfo = new System.IO.FileInfo(dbFile);
66+
if (!dbFileInfo.Directory.Exists)
67+
{
68+
//DBPath doesn't exist -> create it:
69+
dbFileInfo.Directory.Create();
70+
}
71+
//mprattinger
72+
6373
using (var transaction = context.Database.BeginTransaction())
6474
{
6575
try

0 commit comments

Comments
 (0)