Skip to content

Commit 6580b11

Browse files
committed
refactor: minor correctness and clarity cleanups
- AssociationTypeContainer: materialize the projection with ToList so GetAssociationTypes does not rebuild every SqliteAssociationType on each call. - ConnectionStringParser.GetDataSource: reuse the already-parsed dictionary instead of parsing the connection string a second time. - SqliteForeignKeyIndexConvention: fold the uniqueness suffix into the index name before escaping so it stays inside the quoted identifier instead of being appended after the closing quote.
1 parent 81f12d5 commit 6580b11

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

SQLite.CodeFirst/Internal/Convention/SqliteForeignKeyIndexConvention.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ public virtual void Apply(AssociationType item, DbModel model)
7474

7575
private static IndexAnnotation CreateIndexAnnotation(string tableName, string propertyName, int count)
7676
{
77-
var indexName = IndexNameCreator.CreateName(tableName, propertyName);
78-
79-
// If there are two Indicies on the same property, the count is added.
80-
// In SQLite an Index name must be global unique.
81-
// To be honest, it should never happen. But because its possible by using the API, it should be covered.
82-
if (count > 0)
83-
{
84-
indexName = String.Format(CultureInfo.InvariantCulture, "{0}_{1}", indexName, count);
85-
}
77+
// If there are two indices on the same property, the count is appended.
78+
// In SQLite an index name must be globally unique.
79+
// To be honest, it should never happen. But because it is possible via the API, it is covered.
80+
// The suffix is folded in before escaping so it stays inside the quoted identifier;
81+
// IndexNameCreator.CreateName returns an already-escaped name.
82+
string uniquePropertyName = count > 0
83+
? String.Format(CultureInfo.InvariantCulture, "{0}_{1}", propertyName, count)
84+
: propertyName;
8685

86+
var indexName = IndexNameCreator.CreateName(tableName, uniquePropertyName);
8787
var indexAttribute = new IndexAttribute(indexName);
8888
return new IndexAnnotation(indexAttribute);
8989
}

SQLite.CodeFirst/Internal/Utility/AssociationTypeContainer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ internal class AssociationTypeContainer
1010

1111
public AssociationTypeContainer(IEnumerable<AssociationType> associationTypes, EntityContainer container)
1212
{
13-
sqliteAssociationTypes = associationTypes.Select(associationType => new SqliteAssociationType(associationType, container));
13+
// Materialize once. GetAssociationTypes is called per entity set, so a deferred query
14+
// would rebuild every SqliteAssociationType (and its entity-set lookups) on each call.
15+
sqliteAssociationTypes = associationTypes.Select(associationType => new SqliteAssociationType(associationType, container)).ToList();
1416
}
1517

1618
public IEnumerable<SqliteAssociationType> GetAssociationTypes(string entitySetName)

SQLite.CodeFirst/Internal/Utility/ConnectionStringParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static string GetDataSource(string connectionString)
2121
IDictionary<string, string> strings = ParseConnectionString(connectionString);
2222
if (strings.ContainsKey(DataSourceToken))
2323
{
24-
var path = ExpandDataDirectory(ParseConnectionString(connectionString)[DataSourceToken]);
24+
var path = ExpandDataDirectory(strings[DataSourceToken]);
2525
return path.Trim('"');
2626
}
2727

0 commit comments

Comments
 (0)