Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueGeneratedOnAdd index is not reset across InMemoryDatabase instances #7282

Closed
aphex- opened this issue Dec 20, 2016 · 2 comments
Closed

Comments

@aphex-
Copy link

aphex- commented Dec 20, 2016

I wrote some tests using Xunit. Every [Fact] method creates a new DBContext to test.

    var services = new ServiceCollection();
    services.AddEntityFrameworkInMemoryDatabase()
        .AddDbContext<ApplicationContext>(
	    options => options.UseInMemoryDatabase(Guid.NewGuid().ToString()));

An User has the property ID

     protected override void OnModelCreating(ModelBuilder modelBuilder)
     {
          // ...
          modelBuilder.Entity<User>().HasKey(e => e.Id)
          modelBuilder.Entity<User>().Property(f => f.Id).ValueGeneratedOnAdd();
          // ...
     }

As test data I add two users without assigning their ids:

     conext.Users.Add(new User {Name = "Peter"});
     conext.Users.Add(new User {Name = "Paul"});

My DBContext sometimes contains: Peter (id:3) and Paul (id:4) if I run the tests. I am not sure if this only occurs on tests that are using a [Theory].

(If I explicitly set the ids while adding the users it works as expected. This workaround solves the issue in my case.)

Further technical details

EF Core version: "Microsoft.NETCore.App": { "version": "1.1.0", "type": "platform" },
Database Provider: InMemoryDatabase
Operating system: macOS Sierra 10.12.1
IDE: JetBrains Rider 1.0 EAP

@ErikEJ
Copy link
Contributor

ErikEJ commented Dec 20, 2016

InMemory is not a relational provider - it is unfortunate the the extension method is named AddEntityFrameworkInMemoryDatabase rather than AddEntityFrameworkInMemoryProvider or similar

@ajcvickers
Copy link
Member

Dupe of #6872

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants