EntityFramework-Reverse-POCO-Code-First-Generator
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard
Does ReversePoco generate indexes in the config
I have started generating the schema from my model for the first time (Previously this was handled independently) and I have realised that no indexes are annotated in the configs. Is this a setting I am missing somewhere? I couldn't find a reference to indexes in the template configs...
Indexes are part of the entity configuration.. You should see them near the bottom. For example:
public class CustomerConfiguration : IEntityTypeConfiguration<Customer>
{
public void Configure(EntityTypeBuilder<Customer> builder)
{
builder.ToTable("Customers", "dbo");
builder.HasKey(x => x.CustomerId).HasName("PK_Customers").IsClustered();
builder.Property(x => x.CustomerId).HasColumnName(@"CustomerID").HasColumnType("nchar(5)").IsRequired().IsFixedLength().HasMaxLength(5).ValueGeneratedNever();
// etc ...
builder.HasIndex(x => x.City).HasName("City");
builder.HasIndex(x => x.CompanyName).HasName("CompanyName");
builder.HasIndex(x => x.PostalCode).HasName("PostalCode");
builder.HasIndex(x => x.Region).HasName("Region");
}
}
The SQL to check what indexes you have in your database is
SELECT SCHEMA_NAME(t.schema_id) AS TableSchema,
t.name AS TableName,
ind.name AS IndexName,
ic.key_ordinal AS KeyOrdinal,
col.name AS ColumnName,
ind.is_unique AS IsUnique,
ind.is_primary_key AS IsPrimaryKey,
ind.is_unique_constraint AS IsUniqueConstraint,
CASE WHEN ind.type = 1 AND ind.is_primary_key = 1 THEN 1 ELSE 0 END AS IsClustered,
(
SELECT COUNT(1)
FROM sys.index_columns i
WHERE i.object_id = ind.object_id
AND i.index_id = ind.index_id
) AS ColumnCount
FROM sys.tables t
INNER JOIN sys.indexes ind
ON ind.object_id = t.object_id
INNER JOIN sys.index_columns ic
ON ind.object_id = ic.object_id
AND ind.index_id = ic.index_id
INNER JOIN sys.columns col
ON ic.object_id = col.object_id
AND ic.column_id = col.column_id
WHERE t.is_ms_shipped = 0
AND ind.ignore_dup_key = 0
AND ic.key_ordinal > 0
AND t.name NOT LIKE 'sysdiagram%';