File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 11using System . Collections . Generic ;
22using System . Data . Entity . Core . Metadata . Edm ;
3+ using System . Data . Entity . Infrastructure . Annotations ;
34using System . Linq ;
45using SQLite . CodeFirst . Statement ;
56
@@ -27,6 +28,20 @@ private IEnumerable<CreateTableStatement> GetCreateTableStatements()
2728 ICollection < AssociationType > associationTypes =
2829 edmModel . AssociationTypes . Where ( a => a . Constraint . ToRole . Name == entityType . Name ) . ToList ( ) ;
2930
31+ var indexAnnotationGroups = edmModel . EntityTypes . GroupBy ( e => e . Name , e => e . MetadataProperties . OfType < IndexAnnotation > ( ) ) ;
32+ foreach ( var indexAnnotationGroup in indexAnnotationGroups )
33+ {
34+ foreach ( var indexAnnotations in indexAnnotationGroup )
35+ {
36+ foreach ( var indexAnnotation in indexAnnotations )
37+ {
38+ foreach ( var indexAttribute in indexAnnotation . Indexes )
39+ {
40+ }
41+ }
42+ }
43+ }
44+
3045 var tableStatementBuilder = new CreateTableStatementBuilder ( entityType , associationTypes ) ;
3146 yield return tableStatementBuilder . BuildStatement ( ) ;
3247 }
Original file line number Diff line number Diff line change 5454 <Compile Include =" Builder\CreateDatabaseStatementBuilder.cs" />
5555 <Compile Include =" Builder\PrimaryKeyStatementBuilder.cs" />
5656 <Compile Include =" Statement\ColumnConstraint\MaxLengthConstraint.cs" />
57+ <Compile Include =" Statement\CreateIndexStatement.cs" />
5758 <Compile Include =" Statement\PrimaryKeyStatement.cs" />
5859 <Compile Include =" Properties\AssemblyInfo.cs" />
5960 <Compile Include =" SqliteConnectionStringParser.cs" />
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Text ;
4+
5+ namespace SQLite . CodeFirst . Statement
6+ {
7+ internal class CreateIndexStatement : IStatement
8+ {
9+ private const string Template = "CREATE {unique} INDEX {index-name} ON {table-name} ({column-def});" ;
10+
11+ private const string ColumnNameSeperator = ", " ;
12+
13+ public string Name { get ; set ; }
14+ public string Table { get ; set ; }
15+ public IEnumerable < string > ColumnNames { get ; set ; }
16+ public bool IsUnique { get ; set ; }
17+
18+ public string CreateStatement ( )
19+ {
20+ var stringBuilder = new StringBuilder ( Template ) ;
21+
22+ stringBuilder . Replace ( "{unique}" , IsUnique ? "UNIQUE" : string . Empty ) ;
23+ stringBuilder . Replace ( "{index-name}" , Name ) ;
24+ stringBuilder . Replace ( "{table-name}" , Table ) ;
25+
26+ string columnNames = String . Join ( ColumnNameSeperator , ColumnNames ) ;
27+ stringBuilder . Replace ( "{column-def}" , columnNames ) ;
28+
29+ return stringBuilder . ToString ( ) ;
30+ }
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments