Skip to content Skip to sidebar Skip to footer

How To Stop Ef4.1 Code-first To Create Culstered Index For The Entity Pk

With the following simple entity class, EF4.1 Code-First will create Clustered Index for the PK UserId column when intializing the database. public class User { [Ke

Solution 1:

You don't need to predict name of auto generated index. You just need to select name of the index. For SQL server you can use query like:

SELECT I.Name
FROM sys.indexes AS I
INNER JOIN sys.tables AS T ON
    I.object_Id = T.object_Id
WHERE I.is_primary_key = 1AND T.Name = 'Users'

Once you get the name in your custom initializer you can alter old index and create a new one.

Post a Comment for "How To Stop Ef4.1 Code-first To Create Culstered Index For The Entity Pk"