Skip to content

Commit cc0699d

Browse files
committed
Merge pull request #31 from pver/issue_30
Fixes pluralization issue
2 parents b45e249 + b3e55b0 commit cc0699d

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

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
}

0 commit comments

Comments
 (0)