Last active
April 26, 2018 11:33
-
-
Save divinci/4503e13d14d449459aaa88fb9f737676 to your computer and use it in GitHub Desktop.
EntityFrameworkCore/issues/11826
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore; | |
using System; | |
using System.Linq; | |
namespace ConsoleApp1 | |
{ | |
public class TestModel | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
} | |
public class TestContext : DbContext | |
{ | |
public TestContext(string databaseName) | |
: base(new DbContextOptionsBuilder<TestContext>() | |
.UseInMemoryDatabase(databaseName) | |
.Options) | |
{ } | |
public DbSet<TestModel> SomeEntities { get; set; } | |
} | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
using (var context = new TestContext("DatabaseA")) | |
{ | |
context.Set<TestModel>().Add(new TestModel() { Name = "DatabaseAFirstModel" }); | |
context.SaveChanges(); | |
context.Set<TestModel>().ToList().ForEach(m => Console.WriteLine($"{m.Id} : {m.Name}")); | |
/* ---- Prints ---- | |
1 : DatabaseAFirstModel | |
*/ | |
} | |
using (var context = new TestContext("DatabaseB")) | |
{ | |
context.Set<TestModel>().Add(new TestModel() { Name = "DatabaseBFirstModel" }); | |
context.SaveChanges(); | |
context.Set<TestModel>().ToList().ForEach(m => Console.WriteLine($"{m.Id} : {m.Name}")); | |
/* ---- Prints ---- | |
2 : DatabaseBFirstModel | |
*/ | |
} | |
using (var context = new TestContext("DatabaseA")) | |
{ | |
context.Set<TestModel>().Add(new TestModel() { Name = "DatabaseASecondModel" }); | |
context.SaveChanges(); | |
context.Set<TestModel>().ToList().ForEach(m => Console.WriteLine($"{m.Id} : {m.Name}")); | |
/* ---- Prints ---- | |
1 : DatabaseAFirstModel | |
3 : DatabaseASecondModel | |
*/ | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment