2

I have the following code.

private void SeedModule(CentralConfigModel context)
        {
            context.ModuleTypes.AddOrUpdate(
                m => m.Name,
                new DomainModel.ModuleType() { Id = 100, Name = "Device" },
        }

How can I set to force automatic migrations to set Id in newly added record for value 100?

maciejka
  • 818
  • 2
  • 17
  • 42
  • Doesn't Id is the primary column? If it is, EF should be auto-incrementing the key. What will happen, if you have removed explicit setting of Id value here? – Jaliya Udagedara Feb 13 '18 at 11:20
  • I want to remain Id field as PK. When I remove explicit setting, then seed method inserts autoinceremtng values from 1. – maciejka Feb 13 '18 at 11:21
  • Yes, I am sorry, isn't that what you are looking for? – Jaliya Udagedara Feb 13 '18 at 11:23
  • I want to field Id treat as PK. This field shouldn't be incrementted when I insert record via Seed method. I want to put own Id value for each record in seed method. – maciejka Feb 13 '18 at 11:25
  • You need to set identity insert ON. See [here](https://stackoverflow.com/questions/24265300/identity-insert-during-seeding-with-entityframework-6-code-first). – Steve Greene Feb 13 '18 at 14:42

0 Answers0