To solve your problem, after creating the migration file, you must modify the generated code by disabling the clustered index for your primary key, setting false as the value of the clustered PrimaryKey parameter.
After your changes, you should have something like this in the migration file:
CreateTable( "dbo.UserProfiles", c => new { Id = c.Guid(nullable: false), UserID = c.Guid(nullable: false), FieldID = c.Guid(nullable: false), Value = c.String(nullable: false, maxLength: 400), }) .PrimaryKey(t => t.Id, clustered: false) .Index(t => t.UserID, clustered: true, name: "CI_UserProfiles_UserID");
This is not done in the OnModelCreating method using the Fluent API, for example Manish Kumar, but in the migration file. File created using the Add-Migration command.
Existing database
As you say in the comments, your database already exists. After executing the Add-Migration command, you will have this line in your DbMigration file in your Up() method:
public override void Up() { CreateIndex("dbo.UserProfiles", "UserID", clustered: true, name: "CI_UserProfiles_UserID"); }
You must modify the Up() method to have this code:
public override void Up() { this.Sql("ALTER TABLE dbo.UserProfiles DROP CONSTRAINT \"PK_dbo.UserProfiles\""); this.Sql("ALTER TABLE dbo.UserProfiles ADD CONSTRAINT \"PK_dbo.UserProfiles\" PRIMARY KEY NONCLUSTERED (Id);"); this.CreateIndex("dbo.UserProfiles", "UserID", clustered: true, name: "CI_UserProfiles_UserID"); }
In the above code, I assumed that the created clustered index in your database is called PK_dbo.UserProfiles . If not, put the correct name on this place.