Пример #1
0
        public async Task DeleteContainedNavigationLink()
        {
            var serviceRoot   = this.BaseAddress + "/clientTest/";
            var clientContext = new Client.Default.Container(new Uri(serviceRoot));

            clientContext.MergeOption = MergeOption.OverwriteChanges;

            const int albumKey = 0;
            var       album    = await Task.Factory.FromAsync(clientContext.Albums.BeginExecute(null, null), (asyncResult) =>
            {
                return(clientContext.Albums.EndExecute(asyncResult).Where(a => a.ID == albumKey).Single());
            });

            await clientContext.LoadPropertyAsync(album, "Sales");

            Assert.Equal(2, album.Sales.Count);

            var sales = album.Sales.Where(s => s.ID == albumKey + 1).Single();

            clientContext.DeleteLink(album, "Sales", sales);
            await clientContext.SaveChangesAsync();

            await clientContext.LoadPropertyAsync(album, "Sales");

            Assert.Single(album.Sales);
        }
Пример #2
0
        public async Task DeleteNavigationLink()
        {
            var serviceRoot   = this.BaseAddress + "/clientTest/";
            var clientContext = new Client.Default.Container(new Uri(serviceRoot));

            clientContext.MergeOption = MergeOption.OverwriteChanges;

            var singer = await Task.Factory.FromAsync(clientContext.Singers.BeginExecute(null, null), (asyncResult) =>
            {
                return(clientContext.Singers.EndExecute(asyncResult).Where(s => s.ID == 0).Single());
            });

            await clientContext.LoadPropertyAsync(singer, "Albums");

            Assert.Equal(3, singer.Albums.Count);

            var album = await Task.Factory.FromAsync(clientContext.Albums.BeginExecute(null, null), (asyncResult) =>
            {
                return(clientContext.Albums.EndExecute(asyncResult).Where(s => s.ID == 0).Single());
            });

            clientContext.DeleteLink(singer, "Albums", album);
            await clientContext.SaveChangesAsync();

            await clientContext.LoadPropertyAsync(singer, "Albums");

            Assert.Equal(2, singer.Albums.Count);
        }