public async Task <IActionResult> OnPostAsync() { _context.Credentials = CredentialCache.DefaultNetworkCredentials; if (!ModelState.IsValid) { return(Page()); } _context.AddToContractCompany(ContractCompany); _context.BeginSaveChanges(adoSave_RLMember, ContractCompany); var company = _context.ContractCompany; DataServiceQuery <ContractCompany> query = company; TaskFactory <IEnumerable <ContractCompany> > taskFactory = new TaskFactory <IEnumerable <ContractCompany> >(); var kompany = await taskFactory.FromAsync(query.BeginExecute(null, null), iar => query.EndExecute(iar)); ContractCompany2 = kompany.FirstOrDefault(); _context.DeleteObject(ContractCompany2); _context.BeginSaveChanges(adoSave_RLMember, ContractCompany2); return(RedirectToPage("./Index")); }