How to stop EF4.1 Code-First to create Culstered index for the entity PK

前端 未结 1 1290
别那么骄傲
别那么骄傲 2020-12-19 13:38

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

            


        
相关标签:
1条回答
  • 2020-12-19 14:32

    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 = 1 
        AND T.Name = 'Users'
    

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

    0 讨论(0)
提交回复
热议问题