{"action":"closed","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6872","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6872/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6872/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6872/events","html_url":"https://github.com/aspnet/EntityFramework/issues/6872","id":185523249,"number":6872,"title":"Database.EnsureDeleted() should reset any/all ID identity columns for InMemoryDatabase","user":{"login":"ardalis","id":782127,"avatar_url":"https://avatars.githubusercontent.com/u/782127?v=3","gravatar_id":"","url":"https://api.github.com/users/ardalis","html_url":"https://github.com/ardalis","followers_url":"https://api.github.com/users/ardalis/followers","following_url":"https://api.github.com/users/ardalis/following{/other_user}","gists_url":"https://api.github.com/users/ardalis/gists{/gist_id}","starred_url":"https://api.github.com/users/ardalis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardalis/subscriptions","organizations_url":"https://api.github.com/users/ardalis/orgs","repos_url":"https://api.github.com/users/ardalis/repos","events_url":"https://api.github.com/users/ardalis/events{/privacy}","received_events_url":"https://api.github.com/users/ardalis/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-10-26T22:06:31Z","updated_at":"2016-10-31T17:43:11Z","closed_at":"2016-10-31T17:43:11Z","body":"## The Issue\n\nFor testing purposes, you should be able to delete, recreate, and reseed InMemory databases and the result should be the same for each test. Currently identity columns do not reset, so IDs increment with each test iteration.\n### Repro Steps\n\nThis test fails. It should pass.\n\n``` C#\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Threading.Tasks;\nusing Microsoft.EntityFrameworkCore;\nusing Microsoft.Extensions.DependencyInjection;\nusing Xunit;\n\nnamespace EfCoreInMemory\n{\n    public class Item\n    {\n        public int Id { get; set; }\n        public string Name { get; set; }\n    }\n    public class AppDbContext : DbContext\n    {\n        public DbSet<Item> Items { get; set; }\n\n        public AppDbContext(DbContextOptions<AppDbContext> options ):base(options)\n        {\n        }\n    }\n    public class Tests\n    {\n        private static DbContextOptions<AppDbContext> CreateNewContextOptions()\n        {\n            // Create a fresh service provider, and therefore a fresh \n            // InMemory database instance.\n            var serviceProvider = new ServiceCollection()\n                .AddEntityFrameworkInMemoryDatabase()\n                .BuildServiceProvider();\n\n            // Create a new options instance telling the context to use an\n            // InMemory database and the new service provider.\n            var builder = new DbContextOptionsBuilder<AppDbContext>();\n            builder.UseInMemoryDatabase()\n                   .UseInternalServiceProvider(serviceProvider);\n\n            return builder.Options;\n        }\n\n        [Fact]\n        public void Test1()\n        {\n            // create a brand new dbContext\n            var dbContext = new AppDbContext(CreateNewContextOptions());\n\n            // add one item\n            var item = new Item();\n            dbContext.Items.Add(item);\n            dbContext.SaveChanges();\n\n            // ID should be 1\n            Assert.Equal(1, item.Id);\n\n            dbContext.Database.EnsureDeleted();\n\n            Assert.False(dbContext.Items.Any());\n\n            var item2 = new Item();\n            dbContext.Items.Add(item2);\n            dbContext.SaveChanges();\n\n            // ID should STILL be 1\n            Assert.Equal(1, item2.Id);\n\n        }\n    }\n}\n```\n### Further technical details\n\nProject.json:\n\n``` json\n{\n  \"version\": \"1.0.0-*\",\n  \"testRunner\": \"xunit\",\n  \"dependencies\": {\n    \"NETStandard.Library\": \"1.6.0\",\n    \"xunit\": \"2.2.0-beta2-build3300\",\n    \"dotnet-test-xunit\": \"2.2.0-preview2-build1029\",\n    \"Microsoft.AspNetCore.Server.Kestrel\": \"1.0.0\",\n    \"Microsoft.AspNetCore.TestHost\": \"1.0.0\",\n    \"Microsoft.EntityFrameworkCore\": \"1.0.0\",\n    \"Microsoft.EntityFrameworkCore.InMemory\": \"1.0.0\"\n  },\n  \"frameworks\": {\n    \"netcoreapp1.0\": {\n      \"imports\": [\n        \"dotnet5.6\"\n      ],\n      \"dependencies\": {\n        \"Microsoft.NETCore.App\": {\n          \"type\": \"platform\",\n          \"version\": \"1.0.0\"\n        }\n      }\n    }\n  }\n}\n```\n\nVS2015\n"}}
{"actor":{"display_login":"rowanmiller"}}