From b3e55b07e1bcb379a54e00851e8318c9c3afca35 Mon Sep 17 00:00:00 2001 From: pver Date: Mon, 1 Jun 2015 23:11:57 +0200 Subject: [PATCH] Fixes #30 : use storage types instead of entity types --- .../Builder/CreateDatabaseStatementBuilder.cs | 10 +++++----- .../Builder/CreateIndexStatementBuilder.cs | 11 +++++------ .../Builder/CreateTableStatementBuilder.cs | 12 ++++++------ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/SQLite.CodeFirst/Builder/CreateDatabaseStatementBuilder.cs b/SQLite.CodeFirst/Builder/CreateDatabaseStatementBuilder.cs index f8e4f88..570b557 100644 --- a/SQLite.CodeFirst/Builder/CreateDatabaseStatementBuilder.cs +++ b/SQLite.CodeFirst/Builder/CreateDatabaseStatementBuilder.cs @@ -25,21 +25,21 @@ public CreateDatabaseStatement BuildStatement() private IEnumerable GetCreateTableStatements() { - foreach (var entityType in edmModel.EntityTypes) + foreach (var entitySet in edmModel.Container.EntitySets) { ICollection associationTypes = - edmModel.AssociationTypes.Where(a => a.Constraint.ToRole.Name == entityType.Name).ToList(); + edmModel.AssociationTypes.Where(a => a.Constraint.ToRole.Name == entitySet.Name).ToList(); - var tableStatementBuilder = new CreateTableStatementBuilder(entityType, associationTypes); + var tableStatementBuilder = new CreateTableStatementBuilder(entitySet, associationTypes); yield return tableStatementBuilder.BuildStatement(); } } private IEnumerable GetCreateIndexStatements() { - foreach (var entityType in edmModel.EntityTypes) + foreach (var entitySet in edmModel.Container.EntitySets) { - var indexStatementBuilder = new CreateIndexStatementBuilder(entityType); + var indexStatementBuilder = new CreateIndexStatementBuilder(entitySet); yield return indexStatementBuilder.BuildStatement(); } } diff --git a/SQLite.CodeFirst/Builder/CreateIndexStatementBuilder.cs b/SQLite.CodeFirst/Builder/CreateIndexStatementBuilder.cs index 3440bb0..07f4e61 100644 --- a/SQLite.CodeFirst/Builder/CreateIndexStatementBuilder.cs +++ b/SQLite.CodeFirst/Builder/CreateIndexStatementBuilder.cs @@ -4,25 +4,24 @@ using System.Data.Entity.Core.Metadata.Edm; using System.Data.Entity.Infrastructure.Annotations; using System.Linq; -using SQLite.CodeFirst.Extensions; using SQLite.CodeFirst.Statement; namespace SQLite.CodeFirst.Builder { internal class CreateIndexStatementBuilder : IStatementBuilder { - private readonly EntityType entityType; + private readonly EntitySet entitySet; - public CreateIndexStatementBuilder(EntityType entityType) + public CreateIndexStatementBuilder(EntitySet entitySet) { - this.entityType = entityType; + this.entitySet = entitySet; } public CreateIndexStatementCollection BuildStatement() { IDictionary createIndexStatments = new Dictionary(); - foreach (var edmProperty in entityType.Properties) + foreach (var edmProperty in entitySet.ElementType.Properties) { var indexAnnotations = edmProperty.MetadataProperties .Select(x => x.Value) @@ -38,7 +37,7 @@ public CreateIndexStatementCollection BuildStatement() { IsUnique = index.IsUnique, Name = indexName, - Table = entityType.GetTableName(), + Table = entitySet.Table, Columns = new Collection() }; createIndexStatments.Add(indexName, createIndexStatement); diff --git a/SQLite.CodeFirst/Builder/CreateTableStatementBuilder.cs b/SQLite.CodeFirst/Builder/CreateTableStatementBuilder.cs index c8b47e0..225d420 100644 --- a/SQLite.CodeFirst/Builder/CreateTableStatementBuilder.cs +++ b/SQLite.CodeFirst/Builder/CreateTableStatementBuilder.cs @@ -7,19 +7,19 @@ namespace SQLite.CodeFirst.Builder { internal class CreateTableStatementBuilder : IStatementBuilder { - private readonly EntityType entityType; + private readonly EntitySet entitySet; private readonly IEnumerable associationTypes; - public CreateTableStatementBuilder(EntityType entityType, IEnumerable associationTypes) + public CreateTableStatementBuilder(EntitySet entitySet, IEnumerable associationTypes) { - this.entityType = entityType; + this.entitySet = entitySet; this.associationTypes = associationTypes; } public CreateTableStatement BuildStatement() { - var simpleColumnCollection = new ColumnStatementCollectionBuilder(entityType.Properties).BuildStatement(); - var primaryKeyStatement = new PrimaryKeyStatementBuilder(entityType.KeyMembers).BuildStatement(); + var simpleColumnCollection = new ColumnStatementCollectionBuilder(entitySet.ElementType.Properties).BuildStatement(); + var primaryKeyStatement = new PrimaryKeyStatementBuilder(entitySet.ElementType.KeyMembers).BuildStatement(); var foreignKeyCollection = new ForeignKeyStatementBuilder(associationTypes).BuildStatement(); var columnStatements = new List(); @@ -29,7 +29,7 @@ public CreateTableStatement BuildStatement() return new CreateTableStatement { - TableName = entityType.GetTableName(), + TableName = entitySet.Table, ColumnStatementCollection = new ColumnStatementCollection(columnStatements) }; }