How do I temporarily turn off an IDENTITY column in EF Code First?

后端 未结 2 1288
耶瑟儿~
耶瑟儿~ 2020-12-11 06:34

I\'m creating a rewrite of an existing application in EF Code First, but I need to import some of the data from the existing application\'s database. Here\'s the definition

2条回答
  •  忘掉有多难
    2020-12-11 07:30

    You can't. Executing a set identity_insert command changes the behavior of SQL Server, but not the behavior of Entity Framework.

    You have three choices for importing records:

    • Use raw ADO.NET commands (not entities) or ExecuteSqlCommand.
    • Use a different DbContext, in which you define the keys as non-generated.
    • Use a different technology that's more suited for data conversion, like SSIS

提交回复
热议问题