How to Insert Identity by AddOrUpdate methode in Seed
<p>I have an entity that has an identity column. As part of the data-seed I want to use specific identifier values for the "standard data" in my system. 
I dont want disable identity.
only i want to set IDENTITY_INSERT ON in migration seed.</p>

<p>My code is:</p>

<pre><code>protected override void Seed(DelphyWCFTestService.Model.DataContext context)
{
    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Cities] On ");
    context.Cities.AddOrUpdate(
        p =&gt; p.CityId,
        new City { CityId = 1, Title = "Paris" }
    );
}
</code></pre>

<p>but my CityId not insert and identity automaticaly inserted </p>

<p>My Entityframework version is 6.1.3</p>

<p><strong>Update:</strong></p>

<p>I change My code to:</p>

<pre><code>context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Cities] On ");
var cities = new List&lt;City&gt;
{
    new City { CityId = 1, Title = "Paris" }
};
context.Cities.AddRange(cities);
context.SaveChanges();
context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Cities] Off ");
</code></pre>

<p>and the problem is not resolved.</p>