File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
SQLiteEfCodeFirstDbCreator Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Data . Entity ;
33using System . IO ;
4+ using System . Linq ;
45
56namespace SQLiteEfCodeFirstDbCreator
67{
@@ -10,12 +11,21 @@ public class SqliteContextInitializer<T> : IDatabaseInitializer<T>
1011 private readonly bool dbExists ;
1112 private readonly DbModelBuilder modelBuilder ;
1213
13- public SqliteContextInitializer ( string dbPath , DbModelBuilder modelBuilder )
14+ public SqliteContextInitializer ( string connectionString , DbModelBuilder modelBuilder )
1415 {
15- dbExists = File . Exists ( dbPath ) ;
16+ string path = GetPathFromConnectionString ( connectionString ) ;
17+ dbExists = File . Exists ( path ) ;
1618 this . modelBuilder = modelBuilder ;
1719 }
1820
21+ private string GetPathFromConnectionString ( string connectionString )
22+ {
23+ string [ ] keyValuePairs = connectionString . Split ( ';' ) ;
24+ string dataSourceKeyValuePair = keyValuePairs . Single ( s => s . ToLower ( ) . StartsWith ( "data source" ) ) ;
25+ string dataSourceValue = dataSourceKeyValuePair . Split ( '=' ) [ 1 ] ;
26+ return dataSourceValue ;
27+ }
28+
1929 public void InitializeDatabase ( T context )
2030 {
2131 if ( dbExists )
You can’t perform that action at this time.
0 commit comments