AFAIK this is not possible with EntityTypeConfiguration. However you can do this with Code-First migrations. Working example:
public class Product
{
public Guid Id
{ get; set; }
public int Price
{ get; set; }
}
class AppDbContext : DbContext
{
public DbSet<Product> Products
{ get; set; }
}
public partial class InitialCreate : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Products",
c => new
{
Id = c.Guid(nullable: false),
Price = c.Int(nullable: false),
})
.PrimaryKey(t => t.Id, clustered: false)
.Index(t => t.Price, clustered: true);
}
public override void Down()
{
DropIndex("dbo.Products", new[] { "Price" });
DropTable("dbo.Products");
}
}
Result:
CREATE TABLE [dbo].[Products] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[Price] INT NOT NULL,
CONSTRAINT [PK_dbo.Products] PRIMARY KEY NONCLUSTERED ([Id] ASC)
);
GO
CREATE CLUSTERED INDEX [IX_Price]
ON [dbo].[Products]([Price] ASC);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…