diff --git a/SQLite.CodeFirst/Internal/Convention/SqliteForeignKeyIndexConvention.cs b/SQLite.CodeFirst/Internal/Convention/SqliteForeignKeyIndexConvention.cs index e10205e..e5d24ac 100644 --- a/SQLite.CodeFirst/Internal/Convention/SqliteForeignKeyIndexConvention.cs +++ b/SQLite.CodeFirst/Internal/Convention/SqliteForeignKeyIndexConvention.cs @@ -74,16 +74,16 @@ public virtual void Apply(AssociationType item, DbModel model) private static IndexAnnotation CreateIndexAnnotation(string tableName, string propertyName, int count) { - var indexName = IndexNameCreator.CreateName(tableName, propertyName); - - // If there are two Indicies on the same property, the count is added. - // In SQLite an Index name must be global unique. - // To be honest, it should never happen. But because its possible by using the API, it should be covered. - if (count > 0) - { - indexName = String.Format(CultureInfo.InvariantCulture, "{0}_{1}", indexName, count); - } + // If there are two indices on the same property, the count is appended. + // In SQLite an index name must be globally unique. + // To be honest, it should never happen. But because it is possible via the API, it is covered. + // The suffix is folded in before escaping so it stays inside the quoted identifier; + // IndexNameCreator.CreateName returns an already-escaped name. + string uniquePropertyName = count > 0 + ? String.Format(CultureInfo.InvariantCulture, "{0}_{1}", propertyName, count) + : propertyName; + var indexName = IndexNameCreator.CreateName(tableName, uniquePropertyName); var indexAttribute = new IndexAttribute(indexName); return new IndexAnnotation(indexAttribute); } diff --git a/SQLite.CodeFirst/Internal/Utility/AssociationTypeContainer.cs b/SQLite.CodeFirst/Internal/Utility/AssociationTypeContainer.cs index e86d20f..c22d1a9 100644 --- a/SQLite.CodeFirst/Internal/Utility/AssociationTypeContainer.cs +++ b/SQLite.CodeFirst/Internal/Utility/AssociationTypeContainer.cs @@ -10,7 +10,9 @@ internal class AssociationTypeContainer public AssociationTypeContainer(IEnumerable associationTypes, EntityContainer container) { - sqliteAssociationTypes = associationTypes.Select(associationType => new SqliteAssociationType(associationType, container)); + // Materialize once. GetAssociationTypes is called per entity set, so a deferred query + // would rebuild every SqliteAssociationType (and its entity-set lookups) on each call. + sqliteAssociationTypes = associationTypes.Select(associationType => new SqliteAssociationType(associationType, container)).ToList(); } public IEnumerable GetAssociationTypes(string entitySetName) diff --git a/SQLite.CodeFirst/Internal/Utility/ConnectionStringParser.cs b/SQLite.CodeFirst/Internal/Utility/ConnectionStringParser.cs index a146dfb..93592c6 100644 --- a/SQLite.CodeFirst/Internal/Utility/ConnectionStringParser.cs +++ b/SQLite.CodeFirst/Internal/Utility/ConnectionStringParser.cs @@ -21,7 +21,7 @@ public static string GetDataSource(string connectionString) IDictionary strings = ParseConnectionString(connectionString); if (strings.ContainsKey(DataSourceToken)) { - var path = ExpandDataDirectory(ParseConnectionString(connectionString)[DataSourceToken]); + var path = ExpandDataDirectory(strings[DataSourceToken]); return path.Trim('"'); }