public virtual void Repro3101_coalesce_tracking() { CreateDatabase3101(); var loggingFactory = new TestSqlLoggerFactory(); var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .AddSingleton <ILoggerFactory>(loggingFactory) .BuildServiceProvider(); using (var ctx = new MyContext3101(serviceProvider)) { var query = from eVersion in ctx.Entities join eRoot in ctx.Entities on eVersion.RootEntityId equals(int?) eRoot.Id into RootEntities from eRootJoined in RootEntities.DefaultIfEmpty() select new { eRootJoined, eVersion, foo = eRootJoined ?? eVersion }; var result = query.ToList(); var foo = ctx.ChangeTracker.Entries().ToList(); Assert.True(ctx.ChangeTracker.Entries().Count() > 0); } }
public virtual void Repro3101_simple_coalesce1() { using (CreateScratch <MyContext3101>(Seed3101)) { using (var ctx = new MyContext3101()) { var query = from eVersion in ctx.Entities join eRoot in ctx.Entities.Include(e => e.Children).AsNoTracking() on eVersion.RootEntityId equals(int?) eRoot.Id into RootEntities from eRootJoined in RootEntities.DefaultIfEmpty() select eRootJoined ?? eVersion; var result = query.ToList(); } } }
public virtual void Repro3101_conditional() { using (CreateScratch <MyContext3101>(Seed3101)) { using (var ctx = new MyContext3101()) { var query = from eVersion in ctx.Entities.Include(e => e.Children) join eRoot in ctx.Entities on eVersion.RootEntityId equals(int?) eRoot.Id into RootEntities from eRootJoined in RootEntities.DefaultIfEmpty() select eRootJoined != null ? eRootJoined : eVersion; var result = query.ToList(); Assert.True(result.All(e => e.Children.Count > 0)); } } }
public virtual void Repro3101_nested_coalesce2() { using (CreateScratch <MyContext3101>(Seed3101)) { using (var ctx = new MyContext3101()) { var query = from eVersion in ctx.Entities.Include(e => e.Children) join eRoot in ctx.Entities on eVersion.RootEntityId equals(int?) eRoot.Id into RootEntities from eRootJoined in RootEntities.DefaultIfEmpty() select new { One = eRootJoined, Two = 2, Coalesce = eRootJoined ?? (eVersion ?? eRootJoined) }; var result = query.ToList(); Assert.True(result.All(e => e.Coalesce.Children.Count > 0)); } } }
public virtual void Repro3101_complex_coalesce2() { using (CreateScratch <MyContext3101>(Seed3101)) { using (var ctx = new MyContext3101()) { var query = from eVersion in ctx.Entities join eRoot in ctx.Entities.Include(e => e.Children) on eVersion.RootEntityId equals(int?) eRoot.Id into RootEntities from eRootJoined in RootEntities.DefaultIfEmpty() select new { Root = eRootJoined, Coalesce = eRootJoined ?? eVersion }; var result = query.ToList(); Assert.Equal(2, result.Count(e => e.Coalesce.Children.Count > 0)); } } }
public virtual void Repro3101_coalesce_tracking() { using (CreateScratch <MyContext3101>(Seed3101)) { using (var ctx = new MyContext3101()) { var query = from eVersion in ctx.Entities join eRoot in ctx.Entities on eVersion.RootEntityId equals(int?) eRoot.Id into RootEntities from eRootJoined in RootEntities.DefaultIfEmpty() select new { eRootJoined, eVersion, foo = eRootJoined ?? eVersion }; var result = query.ToList(); Assert.True(ctx.ChangeTracker.Entries().Any()); } } }
private static void Seed3101(MyContext3101 context) { var c11 = new Child3101 { Name = "c11" }; var c12 = new Child3101 { Name = "c12" }; var c13 = new Child3101 { Name = "c13" }; var c21 = new Child3101 { Name = "c21" }; var c22 = new Child3101 { Name = "c22" }; var c31 = new Child3101 { Name = "c31" }; var c32 = new Child3101 { Name = "c32" }; context.Children.AddRange(c11, c12, c13, c21, c22, c31, c32); var e1 = new Entity3101 { Id = 1, Children = new[] { c11, c12, c13 } }; var e2 = new Entity3101 { Id = 2, Children = new[] { c21, c22 } }; var e3 = new Entity3101 { Id = 3, Children = new[] { c31, c32 } }; e2.RootEntity = e1; context.Entities.AddRange(e1, e2, e3); context.SaveChanges(); }
public virtual void Repro3101_conditional() { CreateDatabase3101(); var loggingFactory = new TestSqlLoggerFactory(); var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .AddSingleton <ILoggerFactory>(loggingFactory) .BuildServiceProvider(); using (var ctx = new MyContext3101(serviceProvider)) { var query = from eVersion in ctx.Entities.Include(e => e.Children) join eRoot in ctx.Entities on eVersion.RootEntityId equals(int?) eRoot.Id into RootEntities from eRootJoined in RootEntities.DefaultIfEmpty() select eRootJoined != null ? eRootJoined : eVersion; var result = query.ToList(); Assert.True(result.All(e => e.Children.Count > 0)); } }
public virtual void Repro3101_nested_coalesce1() { CreateDatabase3101(); var loggingFactory = new TestSqlLoggerFactory(); var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .AddSingleton <ILoggerFactory>(loggingFactory) .BuildServiceProvider(); using (var ctx = new MyContext3101(serviceProvider)) { var query = from eVersion in ctx.Entities join eRoot in ctx.Entities.Include(e => e.Children) on eVersion.RootEntityId equals(int?) eRoot.Id into RootEntities from eRootJoined in RootEntities.DefaultIfEmpty() select new { One = 1, Coalesce = eRootJoined ?? (eVersion ?? eRootJoined) }; var result = query.ToList(); Assert.Equal(2, result.Count(e => e.Coalesce.Children.Count > 0)); } }