remove auto increment from primary key RRS feed

  • Question

  • Hi,

    In an MVC app with code first I have a table with the key field as Long and the scaffolding made it automatic an auto increment field.

    that is not what I wanted, I want to generate my own key. So I annotated the key field with:


    I ran the migration (Add-Migration and Update-Database) But nothing happens with the Primary key. sneeking in the Generated Migration SQL I do also not find anything that is relevant.

    How can I do this??


    Saturday, December 16, 2017 10:07 AM

All replies

  • Hi rob warning,

    >>How can I do this??

    Based on your description, I create a simple demo and reproduce your issue on my side. Because migrations can’t handle this operation yet, in SQL Server you can’t just make the change with an ALTER statement.

    The following document provide a solution via custom migrations operation for your reference.


    Best regards,

    Zhanglong Wu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 18, 2017 2:52 AM