public virtual void CreateAndDeleteLinkToDerivedNavigationPropertyOnBaseEntitySet() { // clear respository this.ClearRepository("InheritanceTests_Vehicles"); Random r = new Random(RandomSeedGenerator.GetRandomSeed()); // post new entity to repository var car = InstanceCreator.CreateInstanceOf <Car>(r); var vehicle = InstanceCreator.CreateInstanceOf <MiniSportBike>(r, new CreatorSettings() { NullValueProbability = 0.0 }); DataServiceContext ctx = WriterClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4); ctx.AddObject("InheritanceTests_Vehicles", car); ctx.AddObject("InheritanceTests_Vehicles", vehicle); ctx.SaveChangesAsync().Wait(); ctx.SetLink(car, "SingleNavigationProperty", vehicle); ctx.SaveChangesAsync().Wait(); ctx = ReaderClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4); var cars = ctx.CreateQuery <Vehicle>("InheritanceTests_Vehicles").ExecuteAsync().Result.ToList().OfType <Car>(); var actual = cars.First(); ctx.LoadPropertyAsync(actual, "SingleNavigationProperty").Wait(); AssertExtension.PrimitiveEqual(vehicle, actual.SingleNavigationProperty); this.ClearRepository("InheritanceTests_Vehicles"); }
public virtual void AddAndRemoveBaseNavigationPropertyInDerivedType() { // clear respository this.ClearRepository("InheritanceTests_Cars"); Random r = new Random(RandomSeedGenerator.GetRandomSeed()); // post new entity to repository CreatorSettings creatorSettings = new CreatorSettings() { NullValueProbability = 0, }; var car = InstanceCreator.CreateInstanceOf <Car>(r, creatorSettings); var vehicle = InstanceCreator.CreateInstanceOf <Vehicle>(r, creatorSettings); DataServiceContext ctx = WriterClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4); ctx.AddObject("InheritanceTests_Cars", car); ctx.AddRelatedObject(car, "BaseTypeNavigationProperty", vehicle); ctx.SaveChangesAsync().Wait(); ctx = ReaderClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4); var cars = ctx.CreateQuery <Car>("InheritanceTests_Cars"); var actual = cars.ExecuteAsync().Result.First(); ctx.LoadPropertyAsync(actual, "BaseTypeNavigationProperty").Wait(); AssertExtension.PrimitiveEqual(vehicle, actual.BaseTypeNavigationProperty[0]); ctx = WriterClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4); ctx.AttachTo("InheritanceTests_Cars", actual); ctx.AttachTo("InheritanceTests_Vehicles", actual.BaseTypeNavigationProperty[0]); ctx.DeleteLink(actual, "BaseTypeNavigationProperty", actual.BaseTypeNavigationProperty[0]); ctx.SaveChangesAsync().Wait(); ctx = ReaderClient(new Uri(this.BaseAddress), ODataProtocolVersion.V4); cars = ctx.CreateQuery <Car>("InheritanceTests_Cars"); actual = cars.ExecuteAsync().Result.First(); ctx.LoadPropertyAsync(actual, "BaseTypeNavigationProperty").Wait(); Assert.Empty(actual.BaseTypeNavigationProperty); this.ClearRepository("InheritanceTests_Cars"); }