Skip to content

Commit 833bf4e

Browse files
committed
Merge branch 'master' into Issue_22
2 parents a1d1a9f + cbcb9b1 commit 833bf4e

File tree

6 files changed

+32
-33
lines changed

6 files changed

+32
-33
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
Creates a [SQLite Database](https://sqlite.org/) from Code, using [Entity Framework](https://msdn.microsoft.com/en-us/data/ef.aspx) CodeFirst.
77

8-
This Project ships several `IDbInitializer` which creates a new SQLite Database, based on your model/code.
8+
This Project ships several `IDbInitializer` classes. These create new SQLite Databases based on your model/code.
99
I started with the [code](https://gist.github.com/flaub/1968486e1b3f2b9fddaf) from [flaub](https://github.com/flaub).
1010

1111
Currently the following is supported:
@@ -18,23 +18,23 @@ Currently the following is supported:
1818
- Index (Decorate columns with the `Index` attribute. Indices are automatically created for foreign keys by default. To prevent this you can remove the convetion `ForeignKeyIndexConvention`)
1919

2020
I tried to write the code in a extensible way.
21-
The logic is divided into two main parts. Builder and Statement.
21+
The logic is divided into two main parts, Builder and Statement.
2222
The Builder knows how to translate the EdmModel into statements where a statement class creates the SQLite-DDL-Code.
2323
The structure of the statements is influenced by the [SQLite Language Specification](https://www.sqlite.org/lang.html).
2424
You will find an extensive usage of the composite pattern.
2525

2626
## Install
2727
Either get the assembly from the latest [GitHub Release Page](https://github.com/msallin/SQLiteCodeFirst/releases) or install the NuGet-Package [SQLite.CodeFirst](https://www.nuget.org/packages/SQLite.CodeFirst/) (`PM> Install-Package SQLite.CodeFirst`).
2828

29-
The project is builded for the target frameworks 4.0 and 4.5.
30-
That means you can use the SQLite CodeFirst in projects with the following target frameworks.
29+
The project is built to target.NET framework versions 4.0 and 4.5.
30+
You can use the SQLite CodeFirst in projects that target the following frameworks:
3131
- .NET 4.0 (use net40)
3232
- .NET 4.5 (use net45)
3333
- .NET 4.5.1 (use net45)
3434
- .NET 4.5.2 (use net45)
3535

3636
## How to use
37-
If you want to let the Entity Framework create the database, if it does not exist, just set `SqliteDropCreateDatabaseAlways<>` or `SqliteCreateDatabaseIfNotExists<>` as your `IDbInitializer<>`.
37+
When you want to let the Entity Framework create database if it does not exist, just set `SqliteDropCreateDatabaseAlways<>` or `SqliteCreateDatabaseIfNotExists<>` as your `IDbInitializer<>`.
3838
```csharp
3939
public class MyDbContext : DbContext
4040
{
@@ -50,9 +50,9 @@ public class MyDbContext : DbContext
5050
}
5151
```
5252

53-
In a more advanced scenario you may want to populate some core- or test-data after the database was created.
53+
In a more advanced scenario, you may want to populate some core- or test-data after the database was created.
5454
To do this, inherit from `SqliteDropCreateDatabaseAlways<>` or `SqliteCreateDatabaseIfNotExists<>` and override the `Seed(MyDbContext context)` function.
55-
This function will be called, in a own transaction, right after the database was created. This function is only executed if a new database was successfully created.
55+
This function will be called in a transaction once the database was created. This function is only executed if a new database was successfully created.
5656
```csharp
5757
public class MyDbContextContextInitializer : SqliteDropCreateDatabaseAlways<MyDbContext>
5858
{
@@ -67,5 +67,5 @@ public class MyDbContextContextInitializer : SqliteDropCreateDatabaseAlways<MyDb
6767
```
6868

6969
## Hints
70-
If you try to reinstall the NuGet-Packages (e.g. if you want to downgrade to .NET 4.0) the app.config will be overwritten and you may getting an exception when you try to run the console project.
70+
If you try to reinstall the NuGet-Packages (e.g. if you want to downgrade to .NET 4.0), the app.config will be overwritten and you may getting an exception when you try to run the console project.
7171
In this case please check the following issue: https://github.com/msallin/SQLiteCodeFirst/issues/13.

SQLite.CodeFirst/Builder/CreateDatabaseStatementBuilder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ public CreateDatabaseStatement BuildStatement()
2525

2626
private IEnumerable<CreateTableStatement> GetCreateTableStatements()
2727
{
28-
foreach (var entityType in edmModel.EntityTypes)
28+
foreach (var entitySet in edmModel.Container.EntitySets)
2929
{
3030
ICollection<AssociationType> associationTypes =
31-
edmModel.AssociationTypes.Where(a => a.Constraint.ToRole.Name == entityType.Name).ToList();
31+
edmModel.AssociationTypes.Where(a => a.Constraint.ToRole.Name == entitySet.Name).ToList();
3232

33-
var tableStatementBuilder = new CreateTableStatementBuilder(entityType, associationTypes);
33+
var tableStatementBuilder = new CreateTableStatementBuilder(entitySet, associationTypes);
3434
yield return tableStatementBuilder.BuildStatement();
3535
}
3636
}
3737

3838
private IEnumerable<CreateIndexStatementCollection> GetCreateIndexStatements()
3939
{
40-
foreach (var entityType in edmModel.EntityTypes)
40+
foreach (var entitySet in edmModel.Container.EntitySets)
4141
{
42-
var indexStatementBuilder = new CreateIndexStatementBuilder(entityType);
42+
var indexStatementBuilder = new CreateIndexStatementBuilder(entitySet);
4343
yield return indexStatementBuilder.BuildStatement();
4444
}
4545
}

SQLite.CodeFirst/Builder/CreateIndexStatementBuilder.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@
44
using System.Data.Entity.Core.Metadata.Edm;
55
using System.Data.Entity.Infrastructure.Annotations;
66
using System.Linq;
7-
using SQLite.CodeFirst.Extensions;
87
using SQLite.CodeFirst.Statement;
98

109
namespace SQLite.CodeFirst.Builder
1110
{
1211
internal class CreateIndexStatementBuilder : IStatementBuilder<CreateIndexStatementCollection>
1312
{
14-
private readonly EntityType entityType;
13+
private readonly EntitySet entitySet;
1514

16-
public CreateIndexStatementBuilder(EntityType entityType)
15+
public CreateIndexStatementBuilder(EntitySet entitySet)
1716
{
18-
this.entityType = entityType;
17+
this.entitySet = entitySet;
1918
}
2019

2120
public CreateIndexStatementCollection BuildStatement()
2221
{
2322
IDictionary<string, CreateIndexStatement> createIndexStatments = new Dictionary<string, CreateIndexStatement>();
2423

25-
foreach (var edmProperty in entityType.Properties)
24+
foreach (var edmProperty in entitySet.ElementType.Properties)
2625
{
2726
var indexAnnotations = edmProperty.MetadataProperties
2827
.Select(x => x.Value)
@@ -38,7 +37,7 @@ public CreateIndexStatementCollection BuildStatement()
3837
{
3938
IsUnique = index.IsUnique,
4039
Name = indexName,
41-
Table = entityType.GetTableName(),
40+
Table = entitySet.Table,
4241
Columns = new Collection<CreateIndexStatement.IndexColumn>()
4342
};
4443
createIndexStatments.Add(indexName, createIndexStatement);

SQLite.CodeFirst/Builder/CreateTableStatementBuilder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ namespace SQLite.CodeFirst.Builder
77
{
88
internal class CreateTableStatementBuilder : IStatementBuilder<CreateTableStatement>
99
{
10-
private readonly EntityType entityType;
10+
private readonly EntitySet entitySet;
1111
private readonly IEnumerable<AssociationType> associationTypes;
1212

13-
public CreateTableStatementBuilder(EntityType entityType, IEnumerable<AssociationType> associationTypes)
13+
public CreateTableStatementBuilder(EntitySet entitySet, IEnumerable<AssociationType> associationTypes)
1414
{
15-
this.entityType = entityType;
15+
this.entitySet = entitySet;
1616
this.associationTypes = associationTypes;
1717
}
1818

1919
public CreateTableStatement BuildStatement()
2020
{
21-
var simpleColumnCollection = new ColumnStatementCollectionBuilder(entityType.Properties).BuildStatement();
22-
var primaryKeyStatement = new PrimaryKeyStatementBuilder(entityType.KeyMembers).BuildStatement();
21+
var simpleColumnCollection = new ColumnStatementCollectionBuilder(entitySet.ElementType.Properties).BuildStatement();
22+
var primaryKeyStatement = new PrimaryKeyStatementBuilder(entitySet.ElementType.KeyMembers).BuildStatement();
2323
var foreignKeyCollection = new ForeignKeyStatementBuilder(associationTypes).BuildStatement();
2424

2525
var columnStatements = new List<IStatement>();
@@ -29,7 +29,7 @@ public CreateTableStatement BuildStatement()
2929

3030
return new CreateTableStatement
3131
{
32-
TableName = entityType.GetTableName(),
32+
TableName = entitySet.Table,
3333
ColumnStatementCollection = new ColumnStatementCollection(columnStatements)
3434
};
3535
}

SQLite.CodeFirst/SqliteConnectionStringParser.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public static IDictionary<string, string> ParseSqliteConnectionString(string con
2020
foreach (var keyValuePair in keyValuePairs)
2121
{
2222
string[] keyValue = keyValuePair.Split(KeyValueSeperator);
23-
keyValuePairDictionary.Add(keyValue[KeyPosition].ToLower(), keyValue[ValuePosition]);
23+
if (keyValue.Length >= 2){
24+
keyValuePairDictionary.Add(keyValue[KeyPosition].ToLower(), keyValue[ValuePosition]);
25+
}
2426
}
2527

2628
return keyValuePairDictionary;
@@ -29,6 +31,8 @@ public static IDictionary<string, string> ParseSqliteConnectionString(string con
2931
public static string GetDataSource(string connectionString)
3032
{
3133
var path = ExpandDataDirectory(ParseSqliteConnectionString(connectionString)["data source"]);
34+
// remove quotation mark if exists
35+
path = path.Trim('"');
3236
return path;
3337
}
3438

release_appveyor.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ build:
1515
verbosity: normal
1616
after_build:
1717
- ps: >-
18-
Write-Host $env:APPVEYOR_BUILD_FOLDER
19-
2018
cd $env:APPVEYOR_BUILD_FOLDER
2119
2220
cd '.nuget'
2321
2422
./nuget.exe pack '..\SQLite.CodeFirst\SQLite.CodeFirst.csproj' -Properties -Symbols -OutputDirectory '..\SQLite.CodeFirst\bin'
2523
artifacts:
26-
- path: SQLite.CodeFirst\bin\Debug**\SQLite.CodeFirst.*
27-
name: Debug
28-
- path: SQLite.CodeFirst\bin\Release\**\SQLite.CodeFirst.dll
29-
name: Release
24+
- path: SQLite.CodeFirst\bin
25+
name: Assemblies
3026
- path: SQLite.CodeFirst\bin\*.nupkg
3127
name: NuPkg
3228
deploy:
@@ -41,7 +37,7 @@ deploy:
4137
description: https://www.nuget.org/packages/SQLite.CodeFirst/
4238
auth_token:
4339
secure: e3cqaFy9PzI9TAdZJBIDy97Bfbwa7j0EXe2yw7Ev9aJXK0Q+3mnULqb1VU4P7BWR
44-
artifact: Release
40+
artifact: Assemblies,NuPkg
4541
draft: true
4642
on:
4743
branch: master

0 commit comments

Comments
 (0)