public void ExerciseApplyItemsToCollectionViaMergeLists() { MergeOption original = this.context.MergeOption; try { foreach (MergeOption mo in new[] { MergeOption.OverwriteChanges, MergeOption.PreserveChanges }) { using (CustomDataContext.CreateChangeScope()) using (OpenWebDataServiceHelper.PageSizeCustomizer.Restore()) { OpenWebDataServiceHelper.PageSizeCustomizer.Value = (config, type) => { config.SetEntitySetPageSize("Orders", 5); }; NarrowCustomer c0 = new NarrowCustomer() { ID = 0 }; this.context.MergeOption = mo; this.context.AttachTo("Customers", c0); var customers = this.context.CreateQuery <NarrowCustomer>("Customers") .Where(c => c.ID == 0) .Select(c => new NarrowCustomer() { ID = c.ID, Orders = c.Orders.Select(o => new NarrowOrder() { DollarAmount = o.DollarAmount }).ToList() }); foreach (var dummy in customers) { } var customers2 = this.context.CreateQuery <NarrowCustomer>("Customers") .Where(c => c.ID == 0) .Select(c => new NarrowCustomer() { ID = c.ID, Orders = c.Orders.Select(o => new NarrowOrder() { DollarAmount = o.DollarAmount }).ToList() }); foreach (var dummy in customers2) { } // Ensure that we still have the same item count Assert.IsTrue(c0.Orders.Count == 2); } this.ClearContext(); } } finally { this.context.MergeOption = original; } }
public void ExerciseApplyItemsToCollectionViaMergeLists() { MergeOption original = this.context.MergeOption; try { foreach (MergeOption mo in new[] { MergeOption.OverwriteChanges, MergeOption.PreserveChanges }) { using (CustomDataContext.CreateChangeScope()) using (OpenWebDataServiceHelper.PageSizeCustomizer.Restore()) { OpenWebDataServiceHelper.PageSizeCustomizer.Value = (config, type) => { config.SetEntitySetPageSize("Orders", 5); }; NarrowCustomer c0 = new NarrowCustomer() { ID = 0 }; this.context.MergeOption = mo; this.context.AttachTo("Customers", c0); var customers = this.context.CreateQuery<NarrowCustomer>("Customers") .Where(c => c.ID == 0) .Select(c => new NarrowCustomer() {ID= c.ID, Orders = c.Orders.Select(o => new NarrowOrder() { DollarAmount = o.DollarAmount }).ToList() }); foreach (var dummy in customers) { } var customers2 = this.context.CreateQuery<NarrowCustomer>("Customers") .Where(c => c.ID == 0) .Select(c => new NarrowCustomer() {ID=c.ID, Orders = c.Orders.Select(o => new NarrowOrder() { DollarAmount = o.DollarAmount }).ToList() }); foreach (var dummy in customers2) { } // Ensure that we still have the same item count Assert.IsTrue(c0.Orders.Count == 2); } this.ClearContext(); } } finally { this.context.MergeOption = original; } }