99
1010namespace SQLite . CodeFirst . Convention
1111{
12+ /// <summary>
13+ /// Renames the indicies, generated by the
14+ /// <see cref="ForeignKeyIndexConvention"/>-Convention, to match the scheme: "IX_{TableName}_{PropertyName}".
15+ /// This is necessary because in SQLite an index-name must be unique.
16+ /// Must be added right after the <see cref="ForeignKeyIndexConvention"/>-Convention.
17+ /// </summary>
1218 public class SqliteForeignKeyIndexConvention : IStoreModelConvention < AssociationType >
1319 {
1420 private const string IndexAnnotationName = "http://schemas.microsoft.com/ado/2013/11/edm/customannotation:Index" ;
@@ -34,13 +40,15 @@ public virtual void Apply(AssociationType item, DbModel model)
3440 var annotation = GetAnnotation ( edmProperty . MetadataProperties , IndexAnnotationName ) ;
3541 if ( annotation != null )
3642 {
37- // The original attribute is removed. The noneForeignKeyIndicies will be remained and readded without any modification
43+ // The original attribute is removed. The none-ForeignKeyIndicies will be remained and readded without any modification
3844 // and the foreignKeyIncidies will be readded with the correct name.
3945 edmProperty . RemoveAnnotation ( IndexAnnotationName ) ;
4046
47+ // The schema for the automatically generated index name is "IX_{TableName}_{PropertyName}"
4148 var noneForeignKeyIndicies = annotation . Indexes . Where ( index => index . Name != "IX_" + edmProperty . Name ) ;
4249 IndexAnnotation newIndexAnnotation = new IndexAnnotation ( noneForeignKeyIndicies ) ;
4350
51+ // The schema for a FK index, which is generated by the Entity Framework, is "IX_{PropertyName}"
4452 var foreignKeyIndicies = annotation . Indexes . Where ( index => index . Name == "IX_" + edmProperty . Name ) ;
4553 foreach ( var foreignKeyIndex in foreignKeyIndicies )
4654 {
@@ -54,7 +62,6 @@ public virtual void Apply(AssociationType item, DbModel model)
5462 }
5563 }
5664
57-
5865 private static IndexAnnotation GetAnnotation ( IEnumerable < MetadataProperty > metadataProperties , string name )
5966 {
6067 foreach ( MetadataProperty metadataProperty in metadataProperties )
0 commit comments